This is what the Criteria API is for:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On Thu, Jul 6, 2017 at 6:18 AM, Cameron Junge <[email protected]> wrote:

> Hi All,
>
> I'm trying to implement a simple way to filter an association by "enabled"
> entities, but can't seem to figure it out.
>
> As an example, I have a *product*, which has an association to *supplier*
> which can be enabled or disabled (basically a soft delete). By default I
> only want to get enabled *suppliers*.
>
> Basically, it'd be nice if it was possible to define an association on an
> entity that had a filter condition. Eg. *product.suppliers*: "enabled=1".
>
> I know I can use the Repository and always retrieve the enabled
> *suppliers* from it with DQL, but if I want to join *product* against any
> other entity, and access the *suppliers* I run into the problem.
>
> An alternative is to use Criteria and add to *product* an
> *getActiveSuppliers* method. Again, it's only useful after *product*
> hydration whether by DQL or Repository.
>
> I thought of trying table inheritance, but wouldn't that split
> enabled/disabled into 2 different entities? Seems a bit fudgy to delete an
> "enabled" entity and create a new "disabled" entity just to make it
> disabled.
>
> I'm leaning towards Criteria at the moment, but it'd be nice if there was
> some way of defining a join with conditions in the *product*.
>
> Hopefully someone can give me a point in the right direction, would be
> much appreciated!
>
> Cheers, Cameron
>
> --
> 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 https://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 https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to