gpt4 book ai didi

php - CDbCriteria addConditions where 子句不明确

转载 作者:行者123 更新时间:2023-11-29 19:21:33 25 4
gpt4 key购买 nike

我想按日期过滤记录,所以我添加了

createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end']

按照我的标准,但我得到:

CDbCommand failed to execute the SQL statement: 
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'createDate' in where clause is ambiguous

这是我的代码:

     $criteria=new CDbCriteria;
$criteria->with = array(
'Contacts' => array('alias'=> 'Contacts', 'together' => true, ),
'Lisings' => array('alias'=> 'listings', 'together' => true, ),
);
$criteria->addCondition('createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end']);

$result = Model::model('Portfolio')->findAll($criteria);

有什么提示可以修复此错误吗?我也尝试过portfolio.createDate,但它不起作用。

谢谢

最佳答案

在 Yii 1 中,模型表被别名为 t 所以你应该使用:

$criteria->addCondition('t.createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end']);

关于php - CDbCriteria addConditions where 子句不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42409990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com