Project

General

Profile

Actions

Bug #56442

closed

Invalid FileReference used

Added by Xavier Perseguers over 10 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Must have
Category:
Extbase
Target version:
Start date:
2014-02-28
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.4
Tags:
Complexity:
medium
Is Regression:
No
Sprint Focus:

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.


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Task #53514: Extbase: DataMapper causes redundant queriesClosedNico de Haen2013-11-11

Actions
Related to TYPO3 Core - Bug #99505: Useless SQL queries in extbase DataMapperClosedMarkus Klein2023-01-10

Actions
Actions #1

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

Actions #2

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

Actions #3

Updated by Xavier Perseguers over 10 years ago

  • Assignee set to Xavier Perseguers
Actions #4

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"/>
Actions #5

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.

Actions #6

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

Actions #7

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! :-)

Actions #8

Updated by Helmut Hummel over 10 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #9

Updated by Riccardo De Contardi about 7 years ago

  • Status changed from Resolved to Closed
Actions #10

Updated by Markus Klein almost 2 years ago

  • Related to Bug #99505: Useless SQL queries in extbase DataMapper added
Actions

Also available in: Atom PDF