[TYPO3-mvc] Database queries/mapping with associated tables

Franz Koch typo3.RemoveForMessage at elements-net.de
Wed Aug 18 10:36:31 CEST 2010


Hey,

...
> * means that data is mapped from other tables
>
> ->  1 company has n employees
> ->  1 company is in 1 country
> ->  1 company is in 1 region
> ->  1 company has n branches
> ->  1 country has n regions
>
>
>
> i need a list with all employees something like that:
>
> <:f foreach="{company.branches}" as="{branch}">
>      employee {employees.name}: Richard Meyer
>      company {company.name}: Industrial Electronics
>      country {company.country.name}: Netherlands
>      region {company.country.regions.name}: Friesland
>      branches {branch.name}: Electronics
>      ...
>      branches {branch.name}: Electricity
> </f:foreach>

Somehow your example doesn't match your description. If you need a list 
of all employees, why do you loop the branches and not the employees?
Where do your employees come from? Do you prepare those in your 
controller? If so, why? In my eyes it looks like your domain is not well 
formed.

> that works so far
> {branch.name} is only once inside the foreach - the data inside the {}
> braces is just for relation demonstration
>
>
> so because of the mapping it works with $this->companyRepository->findAll()
> to access data the following way:
> $name = $company->getName();
>
> $employees = $company->getEmployees();
> foreach($employees as $e)
>      $e->getName();
> ...

why do you need to do this in your controller? It again looks like a 
design issue in your domain missing some back references.

> now i want to filter the results by countries / branches / regions
> i have been thinking on something like this:
>
> $query->matching(
>      $query->equals('tx_myextension_domain_model_company.country.uid',
> $countryId)
> );
>
> but it doesn't work... i have to do that in the repository - not in the
> model, right?

What do you like to filter? Companies or employees? For companies it 
would look like this:

$query->matching(
       $query->equals('country', /*Tx_YourExt_Domain_Model_Country or a 
plain UID*/ $country)
);

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list