不是Yii的工作范围

时间:2014-02-03 12:25:17

标签: yii

为什么我的示波器不起作用?

$criteria = new \CDbCriteria();                
        $criteria->addCondition('user_id = :user_id');
        $criteria->scopes = array(
            'applicant' => array(
                'scopes' => array('deletedStatus'),
                'params' => array(':deletedStatus' => 0)
            ),
            'filePair' => array(
                'with' => array(
                    'category' => array(
                        'with' => array(
                            'parent' => array(
                                'order' => 'parent.order'
                            )
                        ),
                        'scopes' => array('enabled')
                    ),
                    'file' => array(
                        'scopes' => array('enabled'),
                        'order' => 'file.order'
                    )
                )
            )
        );
        $criteria->params = array(':user_id' => \Yii::app()->userApp->id);
        /** @var \ApplicantDocument[] $models */
        $models = \ApplicantDocument::model()->findAll($criteria);

 public function scopes()
    {
        $t = $this->getTableAlias(false, false);
        return array(
            'deletedStatus' => array(
                'condition' => $t.'.is_deleted = :deletedStatus'
            ),
            'applicant' => array(
                'condition' => $t.'.role = :role',
                'params' => array(':role' => self::APPLICATION_STATUS_APPLICANT)
            ),
            'guarant' => array(
                'condition' => $t.'.role = :role',
                'params' => array(':role' => self::APPLICATION_STATUS_GUARANTOR)
            ),
            'company' => array(
                'condition' => $t.'.role = :role',
                'params' => array(':role' => self::APPLICATION_STATUS_COMPANY)
            ),
            'trust' => array(
                'condition' => $t.'.role = :role',
                'params' => array(':role' => self::APPLICATION_STATUS_TRUST)
            ),
        );
    }

此范围不起作用,从db

中选择了isdeleted的申请人
'applicant' => array(
    'scopes' => array('deletedStatus'),
    'params' => array(':deletedStatus' => 0)
),

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

范围不起作用,因为它在申请人文件中称呼,而不是在申请人中。所以我尝试解决方案,它帮助我。

$criteria->with = array('applicant');
$criteria->together = true;
$criteria->condition = "applicant.is_deleted = 0";