Closed lexisother closed 1 week ago
Hi, thanks for getting in touch! I can’t seem to replicate this. Following your steps, I’m able to get the entry and then the content of the blockImage
Assets field (where blockImage
is the overwritten handle) on that entry.
Could you please share your twig code to get the entry and the content of the blockImage
?
It's a bit difficult to share my Twig code concisely, as it's using a custom matrix block template including system. The general gist of it is as follows:
index.twig
where entry.blocks
is a matrix field with all my entry types:
{% include "_partials/blocks.twig" with { 'blocks': entry.blocks } %}
_partials/blocks.twig
just loops over the blocks and includes _partials/blocks/{block.type}.twig
with block
passed into it.
Where I was encountering the issue was on a matrix block with a field of type Assets where the field handle was blockImage2
, locally aliased to blockImage
in that matrix field. I then tried using block.blockImage.one()
to get my image, which is how I ran into the bug I described.
Only after renaming blockImage2
to imageTextImage
and removing the alias for it did I get the expected result.
I understand the issue is super hazy and probably sounds like a one-off, but this was happening in more places than just my Assets block. I had to give all my matrix blocks unique handles and remove the aliases for them to fix it.
Thanks for sharing more details on this!
Unfortunately, I’m unable to replicate this even after following your template setup.
blockImage2
suggests that maybe you had the same Assets field added to this particular field layout more than once. Would you happen to know if that was the case? It shouldn’t be possible as relational fields are not multi-instance, but a bug allowed this in the early beta version (fixed in 5.0.0-beta.2). Or maybe the field in question was of a different type initially?
It sounds like you have already changed your setup. Do you have a backup (project config or database) of the setup with this problem? If so, could you send it to support@craftcms.com along with composer.json
and composer.lock
and point out the entry where you saw this happen so we can try to replicate and dig deeper?
Now that I reverted my workspace to when I still had the issue, I seem to be unable to reproduce this strange bug... Super unfortunate, because I was hoping this wasn't just a strange one-off. Sorry for bothering!
Thank you for checking, and I’m glad to hear it’s working as expected! Let us know if this happens again in a reproducible way.
What happened?
Description
I am trying to access one of the fields on my entry type using an alias local to that entry type. The field's actual handle is
innovatieImage
, and the handle defined on the entry type isblockImage
. When accessing the field on my entry asentry.blockImage
, I get an emptycraft\elements\ElementCollection
. However, when I remove the field's alias on the entry type (so fromblockImage
to empty, which defaults toinnovatieImage
), I get a filledcraft\elements\db\AssetQuery
on which I can properly call.one()
to retrieve my image.Steps to reproduce
blockImage
and the other calledtestImage
testImage
to an entry type's field layout, and alias it toblockImage
blockImage
on itExpected behavior
The alias works and I correctly get my image.
Actual behavior
I get an empty
ElementCollection
.Craft CMS version
5.2.1
PHP version
8.2.19
Operating system and version
Linux 6.9.3
Database type and version
MariaDB 10.3.39
Image driver and version
Imagick 3.7.0
Installed plugins and versions
No response