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

Any problems with this approach to cancel/abort Async servlet processing

java rest java-ee servlets servlet-3.0

In an Async servlet processing scenario, I want to achieve cancellation of requests.

Uploading file through FTP using PHP

php file-upload ftp

I'm curious how to upload file through FTP using PHP. Let's say I have upload form and user have uploaded a file. How to transfer the file (without moving from temp directory) to some FTP host usin...