[TYPO3-mvc] How to get first object of an 1:n relation

Dmitri Pisarev dimaip at gmail.com
Wed Jun 22 12:50:02 CEST 2011


Hi!
Sorry for bringing up the old thread.
I stuck with the same problem - my code that used to work without 
problem is now broken. This used to work just fine: {place.images.0}
Now I had to add another getter to the Place model and use the 
{place.firstImage}

What has gone wrong with the old approach?

Regards,
Dmitri.
14.04.2011 17:22, Franz Koch пишет:
> Hey,
>
>> i've got an 1:n relation called anhaenge.
>> How i get the first object of anhaenge in a fluid view?
>>
>> Is there a way like
>> {currentObject.anhaenge.first.propertyIlikeToDisplay} ?
>
> not yet. AFAIK there is a review from Felix pending that's implementing
> a "getFirst" method in objectStorages which should actually allow what
> you currently try.
>
> But until this is implemented I'd suggest to do one of the following:
>
> a) simply loop over the "anhaenge"
> b) add a method "getFirstAttachment" to your "currentObject"s domain
> model that's doing the work for you
> c) write a little viewHelper that's able to do what you need
>
> c) would be my favorite because it's most flexible and can be reused for
> other relations.
>



More information about the TYPO3-project-typo3v4mvc mailing list