Reputation: 782
I have following Model:
FilePackage
- ID
- Name
FileGroup
- ID
- Name
- filePackage
File
- ID
- Path
- fileGroup
If i want to get all files for a Group i currently make some queries like.
$groups = $this->fileGroupRepository->findByPackage($package);
foreach($groups as $group){
$files = $this->fileRepository->findByFilegroup($group);
foreach($files as $file){
// Handle it...
}
}
Is it possible to access those directly? Like $groups = $this->fileGroupRepository->findByPackage($package); foreach($groups as $group){ $group->getFiles(); }
Without query everything before and to directly use it in the templates
Upvotes: 1
Views: 1107
Reputation: 124
Depending on the configuration in your TCA Extbase should take care of getting all related objects.
For example:
Filegroup
'files' => array(
'label' => 'LLL:EXT:foo_myext/Resources/Private/Language/locallang_db.xml:tx_foomyext_domain_model_filegroup.files',
'l10n_mode' => 'exclude',
'config' => array(
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'tx_foomyext_domain_model_file',
'foreign_table' => 'tx_foomyext_domain_model_file',
'MM' => 'tx_foomyext_filegoup_file_mm',
'maxitems' => 10,
'minitems' => 0,
'size' => 10,
),
),
File
'filegroups' => array(
'exclude' => 0,
'label' => 'LLL:EXT:tw_foomyext/Resources/Private/Language/locallang_db.xml:tx_foomyext_domain_model_file.filegroups',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_foomyext_domain_model_filegroup',
'foreign_table_where' => 'ORDER BY tx_foomyext_domain_model_filegroup.id',
'MM' => 'tx_foomyext_filegroup_file_mm',
'MM_opposite_field' => 'files',
'size' => 5,
'minitems' => 0,
'maxitems' => 10,
)
),
In your Model these properties should be represented as ObjectStorage.
If you then select a filegroup Extbase will automatically get all related files for you and you will have access to them.
Upvotes: 1