What happened?
Description
I just encountered a bug with an entry query that worked in Craft 4, but is broken in Craft 5:
$categories = $job->jobCategories->select('slug')->column();
$job is an entry and jobCategories is an Entries field. This returned an array of slugs (strings) in Craft 4, but in Craft 5 it's always returning an empty array, regardless of how many entries are selected in the field.
Using ->all() instead of ->column shows the same behaviour. In Craft 4 this returns an array of entries (with all other properties and fields empty, of course). In Craft 5, this still returns an empty array.
I also tried selecting some other fields – id works, but title doesn't. I also tried to explicitly select the table and column (elements_sites.slug), but that isn't working either.
Not sure if I'm doing something wrong here. If the select statement was just wrong, I would get an error, e.g. select('foobar') throws an error.
Notably, if I use a plain entries query without starting from an Entries field, the query works as expected. This returns an array of entry slugs:
Entry::find()->limit(5)->select('slug')->column();
So it might be related to the parameters set by relations fields?
Steps to reproduce
- Add an Entries field to an entry type's field layout.
- Create a new entry and select some entries in the Entries field.
- In the template for the entry, access the Entries field and select the slug using the query above.
Craft CMS version
5.2.8
PHP version
8.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response
What happened?
Description
I just encountered a bug with an entry query that worked in Craft 4, but is broken in Craft 5:
$jobis an entry andjobCategoriesis an Entries field. This returned an array of slugs (strings) in Craft 4, but in Craft 5 it's always returning an empty array, regardless of how many entries are selected in the field.Using
->all()instead of->columnshows the same behaviour. In Craft 4 this returns an array of entries (with all other properties and fields empty, of course). In Craft 5, this still returns an empty array.I also tried selecting some other fields –
idworks, buttitledoesn't. I also tried to explicitly select the table and column (elements_sites.slug), but that isn't working either.Not sure if I'm doing something wrong here. If the select statement was just wrong, I would get an error, e.g.
select('foobar')throws an error.Notably, if I use a plain entries query without starting from an Entries field, the query works as expected. This returns an array of entry slugs:
So it might be related to the parameters set by relations fields?
Steps to reproduce
Craft CMS version
5.2.8
PHP version
8.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response