Hello,
I’m still wondering how to solve the ‘only_full_group_by’ problem building the queries with CakePHP.
I regularly solve it setting this flag off in mysql but I don’t know why it set it back on by itself.
Anyway, I’d like to understand how to fix it.
I again got it today with the following query:
$discoveryBooks = $this->DiscoveryBooks->find('all')
->contain([
'DiscoveryCards'
])
->matching('DiscoveryCards', function ($q) use ($sitesIds) {
return $q
->where([
'DiscoveryCards.site_id IN' => $sitesIds
]);
})
->group(['DiscoveryBooks.id'])
->where([
'published' => true,
'approved' => true
])
->all();
Where it complains about DiscoveryCards.id
which is not aggregated…
Well, according to mysql doc and Cake doc, I tried to do the following:
$discoveryBooks = $this->DiscoveryBooks->find('all')
->contain([
'DiscoveryCards'
])
->matching('DiscoveryCards', function ($q) use ($sitesIds) {
return $q
->select([
'ANY_VALUE(id)' => 'id',
'site_id',
'discovery_book_id',
'name',
'QR_code',
'sequence',
'latitude',
'longitude',
'image',
'copyright',
'directory_name',
])
->where([
'DiscoveryCards.site_id IN' => $sitesIds
]);
})
->group(['DiscoveryBooks.id'])
->where([
'published' => true,
'approved' => true
])
->all();
But in that case it complains about id which is ambiguous.
So I tried:
->select([
'ANY_VALUE(DiscoveryCards.id)' => 'DiscoveryCards.id',
or
->select([
'ANY_VALUE(id)' => 'DiscoveryCards.id',
or
->select([
'ANY_VALUE(DiscoveryCards.id)' => 'id',
It always complains about a syntax error!
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`id`, DiscoveryCards.site_id AS `DiscoveryCards__site_id`, DiscoveryCards.disco' at line 1
Could you please help me to solve this problem?