CakePHP baking self-joined models

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.


id | name


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.

bake is able to generate a self referencing relation (only) if you specified a field named parent_id in your database

Need Your Help

How do I remove a “&” symbol from a URL using regular expressions?

php regex url

how to remove a & Symbol from a url address use php regular?

Robust and easy to implement serial bus (automotive application)

serial-port microcontroller can can-bus

What serial communication bus would you use in a automotive embedded system if your main selection criteria were:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.