Ok, I assume that you have considered your database model careful :)
and based on the first post, you have the following tables (according
to CakePHP conventions for naming tables):
users, companies, addresses, addresses_users, addresses_companies

According to the CakePHP book and information gathered from this
group, when a new user together with an address is entered in a form,
you should first save the user information, then assign the user id to
the address information and save the address.

The same applies when entering a company and its address.

Now as you have settled on a many to many relationship between users
and addresses, I assume further that while entering one user, an
existing address can be assigned to the user in the form. Correct?
In that case, you should only need to save the user information with
the address attached, and CakePHP should automatically create the
addresses_users record.

If I am in error somewhere in the above text, please correct me :)

Hope this helps you on the way!
   John

Ps. I am a thinker and prefer people to think the solution they want,
which is why I write words a lot.



On Feb 6, 3:21 am, Robert K <[email protected]> wrote:
> and actually, I don't think this meets my requirement. since i need to
> be able to do users<>users_addresses<>addresses and the table
> users_addresses is just a hasMany relationship to addresses. because
> these addresses are not types, they are assigned to corporations,
> billing, properties, clients, etc.
>
> On Feb 5, 5:17 pm, Robert K <[email protected]> wrote:
>
> > could you possibly show me exactly how the model would look / table
> > structure ?
> > examples speak louder than words for me.
>
> > On Feb 5, 11:58 am, John Andersen <[email protected]> wrote:
>
> > > Would it not be simpler to have the following tables and associations/
> > > relationships:
>
> > > Tables: users, addresses, addresstypes
>
> > > Models: User, Address, Addresstype
>
> > > With associations/relationships:
> > > User hasMany/belongsTo Address
> > > Address belongsTo/hasMany Addresstype
>
> > > Where addresstypes identifies whether an address is a private address
> > > or a company address (and others if necessary).
>
> > > Thus in a form, the user enters the address, and chooses the
> > > addresstype, saves, and all is well :)
>
> > > Would the above satisfy your requirements?
> > > Enjoy,
> > >    John
>
> > > On Feb 5, 9:26 pm, Robert K <[email protected]> wrote:
>
> > > > user needs to store addresses.
> > > > Address table can store addresses for any type of relationship, users,
> > > > companies, etc.
>
> > > > user_addresses,
> > > > company_addresses, ...
>
> > > > addresses table (id,address1,address2,city,zip,...)
>
> > > > user_addresses (id,user_id,address_id)
> > > > company_addresses (id,company_id,address_id)
>
> > > > so when creating a user, what will happen is not only will cake create
> > > > the relationship bonding in the <obj>_addresses table, but also
> > > > creating the address record in the addresses table.
>
> > > > I could not figure out a legitimate way in cakePHP to do this with the
> > > > saveAll function.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to