If the operation involves simple iteration or collection API usage, then
you can do it in the entity.

If the operation involves access to DQL or *ANY* ORM feature or persistence
in general, then you are not allowed (and shouldn't) to do it in the entity
directly.

It's as simple as that.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 30 March 2014 14:11, Gerard Brouwer <[email protected]> wrote:

> Actually, I want to have all active profiles of active networks of a
> certain account. So I want to ask the Account to give all these items, not
> a repository...
>
> Gerard
>
>
> 2014-03-30 13:57 GMT+02:00 Marco Pivetta <[email protected]>:
>
> Well, it also makes sense that you cannot access the persistence layer
>> from within your entities. It is not up to your entities to "load"
>> associations.
>> The associations are there, you don't assume that you need any database
>> to access them, you just need to traverse them.
>>
>> Otherwise, if you work with the assumption that there is a persistence
>> layer, then you code the fetch logic into a repository, which is the object
>> responsible for loading your entities.
>>
>> Marco Pivetta
>>
>> http://twitter.com/Ocramius
>>
>> http://ocramius.github.com/
>>
>>
>> On 30 March 2014 13:53, Gerard Brouwer <[email protected]> wrote:
>>
>>> Hi Marco,
>>>
>>> Yes that is wat I meant. I already thought so and setted up a custom
>>> repository. But you can't access it from the Entity right? So you have to
>>> call it in a different way in the Controller, which I don't like.
>>>
>>> Gerard
>>>
>>>
>>> 2014-03-30 13:45 GMT+02:00 Marco Pivetta <[email protected]>:
>>>
>>>> If you mean that your property (through which you wanted to filter) is
>>>> not directly defined on the items you are filtering, then Criteria is not
>>>> sufficient. In order to filter data through different associations, you
>>>> either iterate and run checks, or you use callback criteria expressions
>>>> (not lazy, not happening at SQL level) or you use DQL in a custom
>>>> repository.
>>>>
>>>> Marco Pivetta
>>>>
>>>> http://twitter.com/Ocramius
>>>>
>>>> http://ocramius.github.com/
>>>>
>>>>
>>>> On 30 March 2014 11:02, Gerard Brouwer <[email protected]>wrote:
>>>>
>>>>> Marco,
>>>>>
>>>>> Thanks, this seems to work. I saw something about filtering but I
>>>>> assumed it was applied after fetching the data.
>>>>>
>>>>> Ok, what if the Profile is of a Network, which needs to be active too
>>>>> in this case (withing getActiveProfiles method of Account)?
>>>>>
>>>>> Gerard
>>>>>
>>>>>
>>>>> Op zaterdag 29 maart 2014 00:07:07 UTC+1 schreef Marco Pivetta:
>>>>>>
>>>>>> You can filter collections via the criteria api:
>>>>>>
>>>>>> public function getActiveProfiles()
>>>>>> {
>>>>>>     $criteria = new \Doctrine\Common\Collections\Criteria();
>>>>>>      $criteria->andWhere($criteria->expr()->eq('active', true);
>>>>>>
>>>>>>     return $this->profiles->matching($criteria);
>>>>>> }
>>>>>>
>>>>>> See also http://doctrine-orm.readthedocs.org/en/latest/
>>>>>> reference/working-with-associations.html#filtering-collections
>>>>>>
>>>>>> Marco Pivetta
>>>>>>
>>>>>> http://twitter.com/Ocramius
>>>>>>
>>>>>> http://ocramius.github.com/
>>>>>>
>>>>>>
>>>>>> On 28 March 2014 22:48, Gerard Brouwer <[email protected]> wrote:
>>>>>>
>>>>>>>  Hi,
>>>>>>>
>>>>>>>
>>>>>>> I'm starting with Doctrine 2 + Zend Framework 2.
>>>>>>> I have an Entity Account which has a OneToMany relationship to
>>>>>>> Profile. If I call getProfiles on Account, I only want Profile instances
>>>>>>> with the column 'active' = 'yes'. Of course, I want it to call on the
>>>>>>> Account Entity instance (getProfiles() or getActiveProfiles()).
>>>>>>>
>>>>>>> How to do this in the best way? I didn't find a solution for this
>>>>>>> (no annotations, no possibility to access the QueryBuilder within the
>>>>>>> entity).
>>>>>>>
>>>>>>> Gerard
>>>>>>>
>>>>>>> --
>>>>>>> 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.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>> 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.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "doctrine-user" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/doctrine-user/Cx42o5Tduws/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, 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.
>>>>
>>>
>>>  --
>>> 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.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "doctrine-user" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/doctrine-user/Cx42o5Tduws/unsubscribe.
>> To unsubscribe from this group and all its topics, 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.
>>
>
>  --
> 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.
>

-- 
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.

Reply via email to