我的模型中有一些where条件。它的检查是字段活动或否。
现在我需要编写一个连接关系。但我需要删除where条件。有可能吗?
我的模型。
...
public static function find() {
return (new AssetgroupsQuery(get_called_class()))->active();
}
我的关系
public function getAssetgroup(): \app\models\AssetgroupsQuery {
return $this->hasOne(Assetgroups::class, ['asg_id' => 'ass_group'])->andOnCondition(['asg_active' => '1'])
->viaTable('assets', ['ass_id' => 'log_ass_id',]);
}
我需要得到所有活跃的资产并加入,如果资产为空,我需要得到空字段,但模型where条件添加到我的当前sql查询,并删除所有资产为空的字段。我尝试添加一些where条件来删除旧的where,但它不起作用。
你能帮帮我吗?
发布于 2018-07-29 01:20:27
您可以使用where(null)
重置现有条件。
在关系级别上:
public function getAssetgroup(): \app\models\AssetgroupsQuery {
return $this->hasOne(Assetgroups::class, ['asg_id' => 'ass_group'])
->andOnCondition(['asg_active' => '1'])
->where(null)
->viaTable('assets', ['ass_id' => 'log_ass_id',]);
}
或者直接在join:
$query = MyModel::find()
->joinWith([
'assetgroup' => function (ActiveQuery $query) {
$query->where(null);
},
])
https://stackoverflow.com/questions/51570951
复制相似问题