Hey,
the main problem is not to order the result. Maybe the following example
would be better:
Company 1...n Category
Category 1...n Items
To receive the categories of a company with its items i could do
foreach ($company->getCategories() as $category) {
foreach ($category->getItems() as $item) {
...
}
}
The problem here is, that this will result in a lot of database queries
because the associations not loaded until i need them. I know that i could
use the annotation "fetch=EAGER" in my entity but i dont want to load the
categories all the time. So i have to write a method in a repository to
receive the categories with its items in one database query using joins.
But the question is in which repo i have to write that method? The company
or the category repo?
If it would be category repo with a method called
findByCompanyJoinedItems(Company $company) i would have to inject all the
repositories into my company service to receive the associations with its
own associations.
The other way would be a method called
findCategoriesJoinedItemsByCompany(Company $company) in the company repo
and only inject this repo into my service. But somwhow that feels weird...
Hat it being a perfectionism :(
Greets Dominik
Am Freitag, 11. April 2014 17:49:27 UTC+2 schrieb Holtkamp:
>
> @Nima, I meant to define it in the association metadata as described quite
> well here:
> -
> http://doctrine-orm.readthedocs.org/en/latest/tutorials/ordered-associations.html
> -
> http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-orderby
>
> As soon as an Entity is loaded, this particular association would be
> ordered as requested. So no need to 'think' about it anymore as a
> developer, which can be useful in specific cases, which this was.
>
> have a nice weekend!
>
>
> On 11 April 2014 14:52, Nima Sadjadi <[email protected] <javascript:>>wrote:
>
>> Menno,
>> Do you mean somethibg like this?
>> find(...)->orderedBy(...)
>> Does this method work with find() too?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "doctrine-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/doctrine-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.