使用defaultScope属性从模型创建条件时出错来自连接模型

时间:2013-05-17 00:35:59

标签: php activerecord yii

我在event.deleted_at方法模型中添加了来自连接属性(event.statusdefaultScope)的参数:

public function defaultScope()
{
    return array(
            'condition'=>'
                lp_deleted_at is NULL 
                AND event.e_deleted_at IS NULL
                AND event.status = TRUE
        '
    );
}

创建条件时最后一行(addSearchCondition)出错:

 $criteria=new CDbCriteria;



     $criteria->with = array( 
                                     'lokasi_pengamatan'=>array('select'=>'lokasi_pengamatan.nama','together'=>true),
                                     'event'=>array('select'=>'event.id_event','together'=>true)

   $criteria->addSearchCondition('lokasi_pengamatan.nama', '%'.$this->lokasi_pengamatan.'%', false, 'AND', 'ILIKE');

错误消息

Undefined table: 7 ERROR: missing FROM-clause entry for table "event"

1 个答案:

答案 0 :(得分:0)

我通常使用CDbCriteria编写SQL有点不同:

private function searchByUser(){
    $criteria         = new CDbCriteria;
    $criteria->select = 'QuestionForm.*';
    $criteria->addCondition('QuestionForm.user_id = $this->user_id');
    return $this->with(array('QuestionForm'))->findAll($criteria);
}