2015-12-08 22 views
0

我有一个对象作者,一个对象Post和一个对象Comment。 Comment belongs_to的PostPost belongs_to的Author获取他们的父母有一些标准的对象 - Yii

我想获得该帖子的'01-02-2015'和作者生日01-01-1980后后创建的所有评论。

如何为这些规则制定条件/标准?

感谢

回答

1
class Comment extends CActiveRecord { 
    public function search(){ 
     $criteria = new CDbCriteria; 
     $criteria->together = true; 
     $criteria->with = array(
      'post' => array(
       'condition' => "created>='2015-02-01'", 
       'joinType' => "INNER JOIN", 
       'with' => array(
        'author' => array(
         'condition' => "birthday>='1980-01-01'", 
         'joinType' => "INNER JOIN", 
       ) 
      ) 
     ) 
    ); 

     return new CActiveDataProvider($this, array(
      'criteria' => $criteria 
    )); 
    } 
}