Thanks to both you and nurzvy. You are right - the reason I need a HABTM relationship is that two people can share the same phone number.
So the only way to do this (once I get the actual syntax right) will be to save the phones first, gather their ID's, and reformat the data array, and then do a saveAll()? If that's the only way, then I can work with it - I was just hoping for more cake magic... On Mar 10, 4:17 am, WebbedIT <[email protected]> wrote: > You're probably right nurvzy, but if many contacts can have the same > phone number, then he could want a HABTM association. If so there are > a few other issues with his setup > > Table contacts_phone should be contacts_phones, as nurvzy said, but it > also requires an id field (all cake tables require an id field) > > var $hasAndBelongsToMany = 'Phone'; > var $hasAndBelongsToMany = 'Contact'; > > should both be > > var $hasAndBelongsToMany = array('Phone'); > var $hasAndBelongsToMany = array('Contact'); > > But then as nurvzy says your forms are all wrong as the phone ideally > needs to exist before you add your contact and are usually selected > from a multiple checkbox or select list. So you may want to take his > advice and swap to a hasMany association and have the odd duplicate > phone number, but the management of those numbers will be sooo much > easier. > > But if you want to stick with HABTM then you would need to either save > the contact or the phone first and then create the right data array > structure and run a save on the HABTM data, but then how do you offer > future contacts access to the already created phone numbers? > > I would go with hasMany myself, but thought I'd provide the above as > you obviously have not got your head around the use of HABTM so will > come in useful at a future date. > > HTH > > Paul 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 To unsubscribe, reply using "remove me" as the subject.
