[TYPO3-mvc] How to get first object of an 1:n relation
Thomas Kieslich
thomas.kieslich at gmail.com
Wed Jun 22 13:55:26 CEST 2011
Hi, iteratror is a good way, but i believe a little bit slow.
Best way is to read only the first entry in Repository like:
$query->execute()->getFirst();
other way:
//$images = $place->getImages()->toArray();
$images = $place->getImages()->getFirst();
$this->view->assign('images', $images);
if toArray() works getFirst() will work to an you transfer only one
Object to Fluid.
ThomasK
Am 14.04.2011 17:32, schrieb Henjo Hoeksma:
> On 2011-04-14 15:13:46 +0200, Malte Beran said:
>
>> Hi guys,
>> 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} ?
>>
>> Thanks!
>>
>> Malte
>
> Hi Malte,
>
> I right now I would use the iteration option of the for viewhelper:
>
> <f:for each="{anhaenges}" as="anhaenge" iteration="iterator">
> <if condition="{iterator.isFirst}">{anhaenge.value}</f:if>
> </f:for>
>
> Henjo
>
More information about the TYPO3-project-typo3v4mvc
mailing list