Sorry to be a stick in the mud, but have changed the name (seems
obvious now!!) of the second association to DefaultAddress and that
works so it will be staying as is for now. No doubt it will all change
before too long and will try the other way.
Thanks to all for your help,
Duncan
--~--~--
On Dec 1, 2:32 pm, "J.B." <[EMAIL PROTECTED]> wrote:
> As I said in my first post: "just remember to name the associations
> different names "...
> I prefer this method over Rhee's suggestion with a bool for the
> default address in the database... I think it looks nicer and feel
> more OO :)
I
As I said in my first post: "just remember to name the associations
different names "...
I prefer this method over Rhee's suggestion with a bool for the
default address in the database... I think it looks nicer and feel
more OO :)
On Dec 1, 1:37 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Dec 1, 7
On Dec 1, 1:37 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Dec 1, 7:53 am, FrenchEscapes <[EMAIL PROTECTED]> wrote:
>
>
>
> > Well that kind of worked!
>
> > I have put:
>
> > var $hasMany = array(
> > 'Address' => array('className' => 'Address',
> >
On Dec 1, 7:53 am, FrenchEscapes <[EMAIL PROTECTED]> wrote:
> Well that kind of worked!
>
> I have put:
>
> var $hasMany = array(
> 'Address' => array('className' => 'Address',
>'foreignKey' =>
> 'customer_id'
>
Well that kind of worked!
I have put:
var $hasMany = array(
'Address' => array('className' => 'Address',
'foreignKey' => 'customer_id'
),
);
I would put a bool flag in addresses table. Something like
`defaultAddress` as bool, where set to true when default and false on
the other case.
Then you could put WHERE statement into your find function.
On Nov 29, 11:50 am, "J.B." <[EMAIL PROTECTED]> wrote:
> zonium: yes, you're absolutely righ
zonium: yes, you're absolutely right. and I haven't tested it...
Remember to put two associations in the address model as well, address
hasOne (or hasMany, depending on what you want) customer
(default_address_id) and address belongsTo customer...
On 29 Nov, 10:27, zonium <[EMAIL PROTECTED]> wrot
I think your setup is not impractical, in fact it's a very common type
of relationships, for example:
User hasMany Address, and there is one Address that is used as
default
Theme hasMany Layout, and there is one Layout that is set as current
etc.
Using array as Christopher suggested is a solution
This can be done by adding another association, hasOne, on the model.
The customers model will then have one hasOne and one hasMany
association to the same model (addresses), just remember to name the
associations different names and to use default_address_id as the
foreign_key for the hasOne asso
This can be done by adding another association, hasOne... Then the
customers model will have both a hasMany and a hasOne association to
the same table (addresses). Only remember to specify that
default_address_id is the foreign_key for the hasOne association...
I think it's something like that :)
Well, if you already have the default_address_id field in the table,
you can just do some array magic to pull out the one with that Id or,
you can make another call once you have the user array (for a single
user).
Your best bet is to use the array magic goodness with sprinkles and
pluck out what
I have a customers table and an addresses table, customers hasMany
addresses, that bit's easy.
But I want each customer to have a default address in the addresses
table. I have a field 'default_address_id' in the customer table. I
just can't get my head around how to use associations to link them
13 matches
Mail list logo