开发者

CakePHP complex find from three tables dependent

I have three tables:

Stories (id, category_id, sub_category_id, name, story),

Categories (id, parent_id, lft. rght, name), 

SubCategories (id, name) 

They are properly related and all is working fine. But now I need to find stories which belongs to specified category and/开发者_如何学Cor sub_category, by name autocompleate dialog. Example: user entered "dog bone" and must search for such a name in categories/subcategories and after find all stories whitch belongs to found categories. No problem when doing many finds, but in SQL I can make one query. Can this be done in CakePHP in one find ?

Thank you very much!


there are a few options for doing this, some of them below

a) linkable behavior - https://github.com/Terr/linkable/wiki

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

c) adhoc-joins http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find

read up on them and see what suites your needs best.


either you solve it with the table assocations or you use "containable" behavior.

"Containable" Behavior is very easy to use and easy to implement.

Containable Behavior in Cookbook

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜