2012-04-11 55 views

回答

0

3个选择:

1)蛋糕做处理子查询,但它是复杂的: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#sub-queries

这里有一个SO问题必然有一个例子: Subquery in cakePHP to lookup in other table

2)使用加入声明: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables

3)您可以使用您的查询原样通过Model::query()作为只要你先清洁

我更喜欢选项2,因为它不太容易出错,我不必担心消毒/转义。而且一旦你掌握了联结的经验,你会发现自己更经常使用它们。

0

您可以通过两种认定做到这一点。我将假设您的owners_list表的型号名称是OwnersList:

$user_ids = $this->OwnersList->find('list', array(
     'fields'=>array('id','id'), 
     'conditions'=>array(
      'OwnersList.user_id'=>1 
     )   
    )); 

    $results = $this->Post->find('all',array(
     'Post.owner_id'=>$user_ids 
    ));