symfony - QueryBuilder and entity with ManyToMany relation -


in database, have table user (iduser, name...) , table role(idrole, description..). between 2 of them there link table hasrole (iduser, idrole).

generating entity symfony command line, hasrole entity not generated. instead, in user entity have on role property :

* @var \doctrine\common\collections\collection  *  * @orm\manytomany(targetentity="mybundle\entity\role", inversedby="utilisateur")  * @orm\jointable(name="hasrole",  *   joincolumns={  *     @orm\joincolumn(name="utilisateur", referencedcolumnname="id")  *   },  *   inversejoincolumns={  *     @orm\joincolumn(name="role", referencedcolumnname="id")  *   }  * ) 

i create in userrepository method returns of users 1 id role.

it should starts :

$qb = $this->getentitymanager()->createquerybuilder()         ->select('utilisateur')         ->from('accueilbundle:user', 'utilisateur'); 

can u ?

ty

if use doctrine generate manytomany join table, indeed not have entity that.

if need have join table entity (for example because store additional data in table), should create relationship in following way:

entitya <-onetomany-> joinentity <-manytoone-> entityb 

however in case, should suffice role desired id , users that:

$role = $entitymanager->getrepository('role')->find($id); $users = $role->getusers(); //(or getutilisatuers(), if see correctly) 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -