[英]Yii2 GridView: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous
could someone explain me why I'm getting this error?有人可以解释我为什么会收到此错误吗? I've tried to search related information, but couldn't find what would be useful.我试图搜索相关信息,但找不到有用的信息。
Here is my function:这是我的功能:
$query = Recipient::find()->from('recipient')
->joinWith(['delivers'])
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
Error is:错误是:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous SQLSTATE[23000]:违反完整性约束:1052 order 子句中的列“id”不明确
The SQL being executed was:正在执行的 SQL 是:
SELECT COUNT(*) FROM `recipient`
LEFT JOIN `deliver` ON `recipient`.`id` = `deliver`.`recipient_id`
ORDER BY `id` DESC
Try尝试
Recipient::find()->from('recipient')->joinWith(['delivers'])->orderBy(['`recipient`.`id`' => SORT_ASC]);
In above example, column name is explicitly specified to avoid ambiguity error.在上面的示例中,明确指定了列名以避免歧义错误。
Code seems incomplete.代码似乎不完整。 Post more code, so we can help you.发布更多代码,以便我们为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.