Saturday, December 20, 2014

How to associate 3 models (or structure a search) to achieve the following structure (Cake 2.x)

Hi all!

I'm quite new to Cake and this is my first project. 

I'm working on a customer database. For larger business customers the relationships get a little complicated. I have 3 models, Customer, CustomerAddress and CustomerContact. A customer can have many addresses, and many contacts, but the contacts are also based at one address so an address has many contacts.

The end result I'm trying to achieve is to be able to search the data both ways, e.g.

Customer -> Address 1 -> Contact 1
                         
Contact 2
                         
Contact 3
                         
....

           
Address 2 -> Contact 1
                         
....
           
....


Or....

Customer -> Contact 1 -> Address
           
Contact 2 -> Address
           
....

I currently have it working as the first example, but found this problematic when I wanted to search the contacts, I have to search all the addresses too. If I search the contact I want to be able to get the address for that contact too, as in the second example. 

I'm not sure how to set this up, bit of help would be much appreciated to get me on the right track.

TIA! 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: