Hey, first of all, thanks for your guide, helped me alot.

Second, I used your thoughts to solve my problem, which was about paginate and not find itself.

Maybe you might be interested in details about my problem and how I solved it through your solutionm so heres the link with this info:


Best regards,

Kym on 3/28/09

This is fantastic. Thanks so much for posting this. Not only did this help me accomplish exactly what I needed to do, I understand the (un)bind behaviors much better now.


Mitch on 9/4/09

I have been looking for something like this for query that I am working on. While I like the implementation, I think it’s easier just to run a normal SQL query. I still may use it in the future. Thanks.

Les Green on 1/19/10

What about the case when Item HasMany Categories? What manipulations should be done with bind/unbind models?

bancer on 3/27/10


This seems like a very useful article. However the table structure mentioned at the beginning is missing…


Sid on 7/28/10

Sid: whoops, looks like a I lost a file along the ways. Should be fixed now :)

mark story on 7/28/10

Hi Dude,

I have 4 tables like your exemple. But I have a different associations,

Movies —-< Sessions >—- Rooms >—- Theaters

in your exemple was:

Movies —-< Sessions —-< Rooms —-< Theaters

I m developing a Ticket Store, I have this situation and I can create a query using find() to return all movies which belongs to places

I thing which my modeling is wrong but I cant find other way to represent this situation.
I want to represent the theater sallying, so one Theaters hasMany Rooms and Rooms hasMany Sessions each Session hasOne Movie.

Can you help me?
I want when I use the method find() return to me this struct:


[Theater] => array( id => 1, name => ‘SomeTheater’
[Movie] => array( [0] => array( id => 1, title => ‘Shrek 3’ ), [1] => array( id => 1, title => ‘Toy Story’ )


Alex Medeiros on 8/5/10

Yow mark! keep’em coming, your posts are always good, very logical, and pain relieving :) thanks for the post

asdzxc321654 on 9/11/11

http://github.com/rafaelbandeira3/cakephp-plugins/tree/master/behaviors/linkable.php this link is not working.how can i get the file.

saddam on 11/15/11


First off, thanks a mill for this post, it made my problem solving 10x faster, but I am sitting with an unusual problem. Even after removing the bindings and adding them again, the paginator class does not obey them.

For example, I bound a model Vendor to a model Lot, this worked perfectly because I was able to call $data[‘Vendor’] right from the view, telling me it had been associated with no problems.

Yet if I try to filter by Vendor in my paginator:

‘conditions’ => array(‘Vendor.name’ => ‘Simon’)

I get an error that Vendor.name does not exists, how come? I have included the Model in the paginators ‘contain’ key, and the values are all there. I cannot even use the Pagintors sort options on any modals bound using the bindModel method.

Am I missing a very NB step?

Kind regards,

Simon on 12/1/11

Thanks, this covers a gaping hole on the documentation and addressed my issues. Please propose to have this techniques added. No one told me you can set foreign key to false and add your own conditions!!!

Jacob on 1/18/12

All my base are belong to you.

Jonathan on 3/9/12

Thanks, this should be on the CakePHP documentation.

João Lima on 1/3/13

Hello Mark

Why can not Cake determine these muli-level joins automatically into one query?
I am coming from RubyOnRails and if I remembered correcly I only needed to add a :include clause and it was fixed


MartOn on 3/13/13

Hello again Mark
I forgot my other question.
Is it not so that bindModel only works for the next find?

how do I then implement this with paginate? Paginate calls first count then find, so models may unbind?


MartOn on 3/13/13

This is an interesting article, but I do feel that it leads to confusion for developers.

If this is the best way to do it, why does the framework – by standard – implement a different approach? How will anyone know which is best?

Personally I’ve always tried to stick with the framework. To me this means using things like Containable and other components, yet, here we have a core dev saying that this is a better way of doing things?

Perhaps it’s just that the use case isn’t clearly defined for this code.

Neon on 4/5/13

It is probably worth mentioning that bindModel() has a second param “reset” (true/false, defaults to true) which is quite useful if you run multiple queries. And which is necessary in pagination – as the paginator component always needs two queries to get the paginated result (find all for resultset + find count for numbers).

mark on 4/23/13

There is a missing comma between Section and Division subarrays in the hasOne array.

kimsia on 8/3/13

This article saved my bacon and helped a ton! Thanks Mark! Now I have the exact same situation with a hasMany.

Can anyone point us in the right direction for hasMany?

Bryan on 10/2/13

Thanks Dude !! :) Great !

Pratik on 11/12/14