Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Activerecord Yii2活动记录_Activerecord_Yii - Fatal编程技术网

Activerecord Yii2活动记录

Activerecord Yii2活动记录,activerecord,yii,Activerecord,Yii,我是Yii的新手,正在努力想一些事情 我有一个具有此功能的模型: public static function findNonGeo() { $query = new CallerIdentityQuery(get_called_class()); $query->select([ 'cidref', 'caller_id', 'expiry', 'conf_call', 'type', 'redirect', 'destination',

我是Yii的新手,正在努力想一些事情

我有一个具有此功能的模型:

public static function findNonGeo()
{

    $query = new CallerIdentityQuery(get_called_class());
    $query->select([
        'cidref', 'caller_id', 'expiry', 'conf_call',
        'type', 'redirect', 'destination', 'status', 'start_date',
        'statusDesc' => new \yii\db\Expression("CASE status 
            WHEN 0 THEN 'Deactivated' 
            WHEN 1 THEN 'Active' 
            WHEN 2 THEN 'Inactive' 
            WHEN 3 THEN 'Unregistered'
            ELSE 'Permanently Deleted' END")])
        ->where(['status' => '1'])
        ->andWhere(['type' => 'N'])
        ->andWhere(['custref' => Yii::$app->user->identity->typedIdentity->getId()]);
    return $query;
}
在我的控制器中,我这样调用此方法:

 $model = CallerIdentity::findNonGeo()->where(['cidref' => $id])->one();
但是当返回数据时,它就像忽略

->andWhere(['type' => 'N'])
因为我可以查看非“N”类型的记录。 所以我必须在我的控制器里做,也许我做错了什么,或者只是不理解它,但我不明白:

 $model = CallerIdentity::findNonGeo()->where(['cidref' => $id])->andWhere(['type'=>'N'])->one();
使用findOne($id)时的另一件事:

返回null


请提供任何形式的解释/信息

使用
where
时,您设置的是查询的where部分,而不是添加到其中。因此,在
findNonGeo
函数中,您正在构建所需的where部分。但是使用
CallerIdentity::findNonGeo()->where(['cidref'=>$id])
可以删除已经添加的where部分

试着这样做:

CallerIdentity::findNonGeo()->andWhere(['cidref' => $id])->one();
使用
和where
可以保留其他部分,只需添加另一部分即可

CallerIdentity::findNonGeo()->andWhere(['cidref' => $id])->one();