Sql Yii 2可以从模型中重写何处条件?
我的模型中有一些where条件。 其检查为现场激活或否 现在我需要写一个连接关系。但我需要移除where条件。可能吗 我的模特Sql Yii 2可以从模型中重写何处条件?,sql,yii,yii2,yii2-basic-app,Sql,Yii,Yii2,Yii2 Basic App,我的模型中有一些where条件。 其检查为现场激活或否 现在我需要写一个连接关系。但我需要移除where条件。可能吗 我的模特 ... public static function find() { return (new AssetgroupsQuery(get_called_class()))->active(); } 我的亲戚 public function getAssetgroup(): \app\models\AssetgroupsQuery {
...
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',]);
}
我需要获取所有活动资产并加入,如果资产为空,我需要获取空字段,但是
对添加到当前sql查询中的条件进行建模,并删除资产为空的所有字段。
我试图添加一些where条件来删除旧where,但它不起作用
您能帮助我吗?您可以使用
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',]);
}
或直接加入:
$query = MyModel::find()
->joinWith([
'assetgroup' => function (ActiveQuery $query) {
$query->where(null);
},
])
不清楚您想做什么,您能告诉我们您在哪里调用上述关系的代码吗?我使用->where([]),但我不确定它是否正确。使用null是更好的方法吗?在model或controller中更好的方法是什么?空数组也可以工作,但是
null
明确地表示“无where条件”,所以我建议在我的示例中使用它。