To simplify, two entities are defined: User and Comment. User can post many comments and every comment has only one user assigned, thus Comment entity has:
/**
* @var \Frontuser
*
* @ORM\ManyToOne(targetEntity="Frontuser")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ownerUserID", referencedColumnName="id")
* })
*/
private $owneruserid;
However, when in action:
$orm = $this->getDoctrine()->getManager();
$repo = $orm->getRepository('CompDBBundle:Comment');
$repo->findBy(array('owneruserid' => $uid);
Error occured, that there's no such field like owneruserid
.
How can I fetch all the user's comments then? The same happens to similar relations in my DB - looks likes you cannot run find()
with foreign keys as parameters. I believe a function $user->getComments()
should be automatically generated/recognised by Doctrine to allow efficient, quick access to related entities.
The example's simple but, what if there are more entities related to my User in the same way? Do I have to declare repositories for each and try to fetch them by it's owneruserid
foreign keys?