我已经遇到过这样的问题但我不明白在这种情况下如何定义group()
:
我有以下表格:
Articles {
'id',
'name',
}
Categories {
'id',
'name'
}
ArticlesCategories {
'article_id',
'category_id'
}
查询是:
$seconds = $this->Categories->find()
->contain([
'Articles' => function ($q) {
return $q->distinct(['Articles.id']);
}
])
->where([
'Categories.name IN' => $themeNames,
->all();
错误是:
Exception: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'base.ArticlesCategories.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by in [/var/www/mySite/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php, line 36]
因为问题似乎来自联接表,我不知道如何编写group()
子句。