symfony - Doctrine annotaion to return null records in child table -


i want return child records , records have null foreign key's value using doctrine annotation. user entity:

....     /**      * @orm\onetomany(targetentity="appbundle\entity\deliverymethods", mappedby="owner")      */     private $delivery_methods;  .... 

and here delivery method entity(table child rows):

....     /**      * @orm\manytoone(targetentity="appbundle\entity\user", inversedby="delivery_methods")      * @orm\joincolumn(name="owner", nullable=true)      */     private $owner; .... 

what change need make in annotations?

thanks

you can write new repository class , add below :

class deliverymethodsrepository extends entityrepository {      /**      *       * @param type $owner      * @return type      */     public function getownerassociatedororphanentities($ownerid) {          $qb = $this->createquerybuilder("dm")             ->andwhere("dm.owner = :owner or dm.owner = null")             ->setparameter("owner", $ownerid);          return $qb->getquery()->execute();     } } 

and call method deliverymethod repository controller.

please note : can write custom query builder inside controller method.

hope helps!


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) -