2015-12-08 32 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 
    )); 
    } 
}