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

Claus Due claus at wildside.dk
Wed Jun 22 14:09:43 CEST 2011


Hi Thomas,

What you write does NOT work for ObjectStorage.

QueryResult supports getFirst(), ObjectStorage does not - hence: $place->getImages()->toArray() (optionally, shift the first child off the array).

I do agree, though. If only one image is needed, only one image should be pulled from DB. However, if $place is already loaded and needed then array_shift() on ->toArray() result is just fine  - and it does seem like this is true according to the description/varnames.

--

Med venlig hilsen / Kind regards

Claus Due
Code Monkey
--
Wildside A/S
Katrinebjergvej 113, DK-8200 Århus N
tlf. 86 12 64 65
http://www.wildside.dk

On Jun 22, 2011, at 1:55 PM, Thomas Kieslich wrote:

> $images = $place->getImages()->getFirst();



More information about the TYPO3-project-typo3v4mvc mailing list