Bug #56442
closedInvalid FileReference used
100%
Description
In my domain model (watches) I have this:
family (1:n) familyLine (1:n) watch (1:1) image
Thus a family has some familyLines which in turns have watches and each watch has an associated image (FileReference).
As "image" is a FileReference, column "image" from table "watch" is a counter of how many references are associated, thus "1" in my case since there is only one allowed image to be linked.
familyLines are lazy loaded, watches too and image reference as well.
When I loop over my families in the view, I basically do this:
foreach families as family foreach family.familyLines as familyline show familyline.<first-reference>.image endforeach endforeach
Now, the first image to be loaded will put the corresponding FileReference's uid into memory. In my case this happens to be sys_file_reference row with uid=1. When I loop over the second picture to be retrieved (from lazy loading), it has to map value "1" (which actually is not a uid but a counter) as a FileReference and as such it finds the first FileReference that was retrieved before and it does not load the actual FileReference but the previous one.
In the end this means that it shows the first image instead of the real one.
Updated by Xavier Perseguers over 10 years ago
- Status changed from New to On Hold
The problem is actually not related to Extbase, but my domain model as I type-hinted the domain model property as a FileReference whereas it's actually a ObjectStorage of FileReference's. Must see if a single FileReference is possible with FAL.
Extbase is properly seeing the relation as RELATION_HAS_ONE
Updated by Gerrit Code Review over 10 years ago
- Status changed from On Hold to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27949
Updated by Xavier Perseguers over 10 years ago
- Assignee set to Xavier Perseguers
Updated by Marc Bastian Heinrichs over 10 years ago
I consider this not as a bug.
A relation to filereference is 1:n by design - also, if max in tca is set to one.
The image property should be defined:
/** * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> * @lazy */ protected $image;
In the fluid template you have to iterate over the image to render the single one or you could use the iteratorFirstVH of vhs.
{namespace v=Tx_Vhs_ViewHelpers} <v:var.set name="firstImage" value="{v:iterator.first(haystack: images)}" /> <f:image src="{firstImage.uid}" class="{cssClass}" alt="" maxWidth="{settings.imageMaxWidth}" height="{imageHeight}" width="{imageWidth}" treatIdAsReference="TRUE"/>
Updated by Helmut Hummel over 10 years ago
Marc Bastian Heinrichs wrote:
I consider this not as a bug.
A relation to filereference is 1:n by design - also, if max in tca is set to one.
I tend to agree. It would be consistent.
However, the whole Extbsase persistent can deal with the situation that
the relation is one to one, but the relation is defined on the child (parentKeyFieldName is set).
Besides that, what makes it now break is the caching introduced in #53514
So my suggestion would be to let the method mapObjectToClassProperty() deal with that
and act accordingly.
Updated by Gerrit Code Review over 10 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/27949
Updated by Marc Bastian Heinrichs over 10 years ago
Sorry Xavier, misinterpreted the whole thing.
Of course the example with a 1:1 relation with irre
worked before introducing the cache in #53514.
Thanks for finding this bug! :-)
Updated by Helmut Hummel over 10 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 04f66dba2538cfc3c7de8578e4f2bd35900702af.
Updated by Riccardo De Contardi almost 7 years ago
- Status changed from Resolved to Closed
Updated by Markus Klein over 1 year ago
- Related to Bug #99505: Useless SQL queries in extbase DataMapper added