Cakephp using bindmodel to get to deep relations

http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations

 

Now we want to find the Division that a particular Item belongs to. In normal SQL we could do

Show Highlighted Code

And everything will happen in one query. In CakePHP we could use Containable to get at these deep relations. With a find call like

Show Highlighted Code

This will work just fine however, it will also do 3 queries, one per table. In order to get the optimal query and stay inside the realm of non query() function we can use some bindModel() trickery.

Show Highlighted Code

The above although much longer will create only one query. This will provide the fastest result performance wise.

4 ماه پیش

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

This site uses Akismet to reduce spam. Learn how your comment data is processed.