YIi2-比较searchModel中的两个字段
我有一个名为tpourchasing的表,其中包含有关商店购买记录的数据 t采购YIi2-比较searchModel中的两个字段,yii2,Yii2,我有一个名为tpourchasing的表,其中包含有关商店购买记录的数据 t采购 id |序列号 事务|时间戳,无时区 供应商|字符变化(200) 总|双精度 付费|双精度 通过在yii2中使用gii特性,我从“CRUD生成器”菜单中生成了一个名为TPurchasingSearch的模型。在TPurchasingSearch中,有一个名为search()的函数,该函数由视图文件中的GridView使用 public function search($params) { $query
- id |序列号
- 事务|时间戳,无时区
- 供应商|字符变化(200)
- 总|双精度
- 付费|双精度
public function search($params)
{
$query = TPurchasing::find();
$dataProvider = new ActiveDataProvider([
'pagination' => ['pageSize' => 20],
'query' => $query,
'sort' => ['defaultOrder' => ['transaction_time' => SORT_DESC]]
]);
$this->load($params);
if (!$this->validate()) {
$query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['is_removed' => 0]);
$query->andFilterWhere(['like', 'supplier_name', $this->supplier_name])
->andFilterWhere(['like', 'payment_type', $this->payment_type])
->andFilterWhere(['>', 'total', 'paid']);
return $dataProvider;
}
现在我正试图显示尚未完全付清的记录,这意味着“已付”列小于“总计”列。如何在搜索功能中进行此比较?上面的代码给了我一个错误:
invalid input syntax for type double precision: "paid"
在这方面
->andFilterWhere(['>', 'total', 'paid']);
因为它试图将合计列与字符串“paid”进行比较。我可能错过了,但我似乎在Yi2文档中找不到相关的答案。无需使用
和filterwhere()
在这里,您只需尝试:
$query->andWhere('total > paid');
无需在此处使用
和filterwhere()
,您只需尝试:
$query->andWhere('total > paid');
它成功了!没想到会这么简单。谢谢它成功了!没想到会这么简单。谢谢