I am trying to setup a self join and having hell.
For example, a User has a ContactList, which is just other Users. So ContactList is a join table connecting User to itself.
User
id | name
ContactList
id | user_id | friend_id
After baking however, im not getting the result i expect. I’ve googled solutions but they dont work for me. How is this kind of situation handled? Do i need to customize the model?
The solution is to set up your associations manually, per the CakePHP book [Associations].
How can CakePHP know what you’re referring to with “friend_id” if there’s no “friends” table? Hint: it can’t.
There are plenty of great examples in the book on the page about Associations (the link above). Read through it and you’ll most definitely have a better understanding.
It’s not really considering “customizing the model” by doing things that aren’t baked for you. Baking is just a quick way to get the bare-bones up and rolling, but it can’t be expected to do ALL the work.