I have an entity "Note", that links to my entity "User" in a ManyToMany Relationship. From my User entity, I want to get all Notes that match certain criteria.
I know the via ORM you can do this:
$this->getDoctrine()->getRepository('PmbLicensingBundle:Note')->findBy(array('criteria' => $value));
Is the same thing possible by invoking a method on an entity, for instance:
$this->getUser()->getSharedNotes(array('criteria' => $value));
Alternatively, is there a way to use the former ORM command to filter within a ManyToMany relationship, for instance:
$this->getDoctrine()->getRepository('PmbLicensingBundle:Note')->findBy(array('criteria' => $value, sharedUsers CONTAINS $this->getUser()));
Excerpt from Entity User.php:
/**
* User
*
* @ORM\Entity
* @ORM\Table(name="users")
* @Ser\ExclusionPolicy("all")
*/
class User implements AdvancedUserInterface, \Serializable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Ser\Expose
*/
protected $id;
/**
* @var User[]
*
* @ORM\ManyToMany(targetEntity="Pmb\LicensingBundle\Entity\User", inversedBy="sharedNotes")
* @Ser\Expose
**/
protected $sharedUsers;
...
}
Excerpt from Entity User.php
/**
* User
*
* @ORM\Entity
* @ORM\Table(name="users")
* @Ser\ExclusionPolicy("all")
*/
class User implements AdvancedUserInterface, \Serializable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Ser\Expose
*/
protected $id;
/**
* @var Note[]
*
* @ORM\ManyToMany(targetEntity="Pmb\LicensingBundle\Entity\Note", mappedBy="sharedUsers")
* @Ser\Expose
**/
protected $sharedNotes;
...
}
Alternatively, what is the recommended solution matching criteria on a ManyToMany or OneToMany property? I would prefer to execute this without relying on an Entity Manager.