Find conditions with hasMany model

前端 未结 2 1032
梦如初夏
梦如初夏 2020-12-10 08:12

I have 4 model:

Item------hasMany---->Detail

Item------hasMany---->Favourite

Item------hasMany---->Category

How can I find all Item that has

2条回答
  •  情话喂你
    2020-12-10 09:04

    You could also try something like this:

    $this->Item->hasMany['Favorite']['conditions']['member_id'] = 8;
    

    Which has the same effect as rebinding the model with the condition.

    Just a possible issue. The above will add the condition for the rest of the request, if you want to rollback to the previous behavior, you need to unset the condition:

    unset($this->Item->hasMany['Favorite']['conditions']['member_id']);
    

    Remember to set the $this->Item->recursive property to the desired value (recursive attribute). The default it's 1, which it's the minimum you need for this to work.

提交回复
热议问题