0
votes

I have TYPO3 extension with some custom function in repository. I have in this model 1:n relation (events is parent and dates are child elements).

I tried to get the beginning date of child elements with

foreach($events as $key => $value) {
        echo $value->getDates()->getBeginn();
    }

But I get error "Call to undefined method TYPO3\CMS\Extbase\Persistence\ObjectStorage::getBeginn()". How can I initalize the ObjectStorage in repository?

Thanks Martin

1

1 Answers

1
votes

If I understand you correctly, getBeginn is a function in the Date model and each Event object can have multiple Date objects attached to it.

Assuming this is correct, the getDates function in an Event object will return a collection of Date objects, not just one. In TYPO3 this is done using an ObjectStorage. You can see (and use) this as an array which (in this case) contains Date objects.

So for example you can do:

foreach($events as $event) {
    foreach ($event->getDates() as $date) {
        echo date->getBeginn();
    }
}