-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x]: Entry field queries returning _all entries_ if the id()
param is used to exclude entry IDs
#15570
Comments
Hi @mmikkel, thanks for reporting! The fact that after resaving there’s no more join with the relations table is expected. With making the relation fields multi-instance, their content is now saved in the I do see what’s causing the |
While we discuss the solution for this, worth noting that you can resolve by setting the ID condition using entry.myRelationField.andWhere(['not', ['id' => 123]]) |
@brandonkelly Good to know, thanks. Excepting the current behavior, in what way can using |
Fixed for the next release.
Relational field queries have always used the |
Fantastic, thanks both!
TIL! Might be more careful with that going forward – but nevertheless, it's a relief that it was possible to restore the pre-5.3 behaviour :) |
Craft 5.4.0 is out now with that fix. Thanks again! |
What happened?
Description
Since upgrading from 5.2.10 to 5.3.4, I'm seeing some odd behaviour with entry queries derived from Entries fields, where adding an
.id(['not', id)
param to the entry field query results in the query returning every single (non-nested) entry in the site (except the one(s) with the excluded ID(s)), i.e. completely disregarding the actual relations in the field.Prior to 5.3.4, this query would return entries related to
entry
in the fieldentriesField
, except an entry with the ID23432234
:On 5.3.4, the above query will return all entries in the site (except any with the ID
23432234
).Crucially, this only appears to happen if the source entry has been re-saved after upgrading to 5.3.4. I.e. immediately after upgrading to 5.3 things work as before, but once the relation source
entry
is re-saved (either manually or via CLI), the described behaviour manifests.I dumped the raw SQL from
entry.entriesField.id(['not', 23432234])
before and after upgrading the site to 5.3.4 (and re-saving the entry) – here's a diff to highlight what changed (likely relevant, theINNER JOIN relations
part is somehow gone): https://www.diffchecker.com/l25MWZtQ/ (the SQL from 5.2.10 is on the left; 5.3.4 on the right).I'm able to reproduce this on a brand new 5.2.10 install after upgrading to 5.3.4; here's some steps for a reduced test case:
Steps to reproduce
entriesField
, and add it to the entry type(The element ID in the
.id(['not', ..)
param is completely fictional, and it doesn't matter; the important thing is that the.id()
param with the'not'
directive, is used).As expected, the output should be
craft resave/entries
CLI commandExpected behavior
Adding
.id(['not', id])
to an entry field query should return related entries excepting the one with the specified ID.Actual behavior
After resaving the source entry in Craft 5.3.4, adding
.id(['not', id])
to an entry query results in all entries except the excluded one being returned, regardless of the entry field's actual relations.Similarly, adding
.id(id)
to the entry query results in the entry with the specifiedid
being returned, even if it is not in fact related to the source entry in the entries field.Craft CMS version
5.3.4
PHP version
8.2.20
Operating system and version
macOS, DDEV v1.23.3
Database type and version
Ver 8.0.36 for Linux on aarch64 (Source distribution)
Image driver and version
No response
Installed plugins and versions
None
The text was updated successfully, but these errors were encountered: