Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2 : Applying a filter to an association

For example if I have :

class Parent {

/* ... */

/** One to Many association */
protected $children;

}

class Child
{
/* .. */
/** many to one association */
protected $parent;

/* name of child column */
protected $name;
}

Now, let's say for a parent, I want to filter the children by their name. If possible, somehow doing parent.getChildren() with this filter would be nice but that's impossible.

I'd like it to probably have the syntax getChildrenByName(), but this function seems unfitting for the ORM class and it's repository class. Does anyone have any suggestions?

like image 583
DubyaDubyaDubyaDot Avatar asked Jul 09 '12 18:07

DubyaDubyaDubyaDot


1 Answers

This feature allows you to add criteria when fetching associations:

Working With Associations: Filtering Collections

  • Version 3.0
  • Version 2.7
like image 179
Vincent Wasteels Avatar answered Oct 13 '22 06:10

Vincent Wasteels