CakePHP containable conditions not limiting results?

徘徊边缘 提交于 2019-12-06 00:06:51

You cannot limit your main Model's results based on conditions within the Contain. When you use contain(), it actually creates multiple queries - that keeps you from being able to limit based on contained conditions.

To resolve this, you need to use JOINs [ see CakePHP Joining Tables ] instead of contain.

If you want nested formatting, could you move all this to another (e.g Groceries) controller which would allow you to limit by user_id or (but I have to admit that I'm not sure whether this is good Cake practice, although I have successfully used this approach...in 1.3 anyway) something along the lines of:

$groceries = $this->Category->Item->Grocery->find('all', array(
    'conditions' => array(
         Grocery.user_id =' => $this->Auth->user('id')
    )
));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!