Persistence · प्रश्न 6 / 12
Extbase model में कई संबंधित objects रखने वाली property के लिए, जैसे किसी conference के सभी speakers, आप कौन-सा type उपयोग करते हैं?
1 उत्तर सही है। आसान
उत्तर दिखाएँ
उत्तर
- A \
TYPO3\ CMS\ Extbase\ Persistence\ ObjectStorage
व्याख्या
1:n और m:n relations के लिए Extbase class ObjectStorage उपयोग करता है, जैसे protected ObjectStorage $speakers; साथ में IDE और static analysis के लिए annotation @var ObjectStorage<Speaker>। Entries addSpeaker() जैसे methods से जोड़ी जाती हैं, जो अंदर attach() call करते हैं, और detach() से हटाई जाती हैं। Template में आप relation पर <f:for each="{conference.speakers}" as="speaker"> से iterate करते हैं। ObjectStorage को access करने से पहले initialise करना ज़रूरी है, वरना error आता है। PHP का SplObjectStorage मिलता-जुलता दिखता है, लेकिन Extbase उसमें relations load नहीं कर सकता और न ही उसके बदलाव persist कर सकता है।