如何为关系创造条件Yii

时间:2014-02-03 14:37:28

标签: yii

我在Yii有关系:

public function relations() {
        return array(
            'applicant' => array(
                self::BELONGS_TO,
                'ApplicantProfile',
                array('applicant_id' => 'id'),
            ),
            'filePair' => array(
                self::BELONGS_TO,
                'DocumentCategoryFile',
                array('file_pair_id' => 'id'),
                'joinType' => 'inner join'
            )
        );
    }

我如何在addCondition中为申请人创建CDbCriteria(),例如我想要is_deleted = 0。我试了$criteria->with = array('applicant' => array('join'=>'left join','condition'=>' aplicant .is_deleted = 0'));但我有sql语法错误 感谢

1 个答案:

答案 0 :(得分:1)

试试这个 -

          $criteria = new CDbCriteria();
          $criteria->with = array('applicant');
          $criteria->together = true;
          $criteria->addCondition('applicant.is_deleted=0');

您应该参考链接here以了解如何使用它。