symfony - doctrine2 symfony2 relations entities -
i have big problem.
1 . have class user of fos have form of register supervisors , process of registration works well.
2 . every supervisor has personals , has form of adding personal , form registration of supervisor , add process in same class of supervisor class user .
--> supervisor , personals there in same class .
the question :
when supervisor login how select him personals , there in same table ?
suggestions :
1 . manytoone , onetomany in same class user 2 attributes parent , childs :
/** * @orm\onetomany(targetentity="common\authenticationbundle\entity\user", mappedby="parent") */ protected $childs; public function __construct() { $this->childs = new arraycollection(); } /** * @orm\manytoone(targetentity="common\authenticationbundle\entity\user", inversedby="childs") * @orm\joincolumn(nullable=false) */ private $parent;
i don't know how work ?
2 . create class supervisorpersonal put supervisor_id , personal_id when supervisor add new personal.
this has problem of mapping doctrine what's relation between 2 class , how doctrine migration of key ?
the ideal way of implementing scenario create many 1 relation on user class. many 1 relation represent many personal belong user class having relations single supervisor, again belongs same user class.
in yml config can represented
manytoone: supervisor: targetentity: common\authenticationbundle\entity\user joincolumn: name: supervisor_id referencedcolumnname: id
and annotation
/** * @manytoone(targetentity="common\authenticationbundle\entity\user") * @joincolumn(name="supervisor_id", referencedcolumnname="id") **/ private $supervisor;
to personals supervisor, have write repository function takes supervisorid parameter.
public function getallpersonslsforsupervisor($supervisorid) { $em = $this->getentitymanager(); $query = $em->createquery("select e authenticationbundle:user e e.supervisor = :supervisor") ->setparameter('supervisor', $supervisorid); $entities = $query->getresult(); return $entities; }
you may have give correct namespace entity in query.
Comments
Post a Comment