Tuesday 15 April 2014

php - InnerJoin with Doctrine2 (Symfony2) -



php - InnerJoin with Doctrine2 (Symfony2) -

i new symfony2 (~ 1 week). have manytoone on budgetdata entity joins id of entity budgetdescription. created sql query want replicate doctrine :

class="lang-sql prettyprint-override">select d, e budgetdata d inner bring together budgetdescription e on d.budgetdescription_id = e.id

budgetdata table : id, year, value, budgetdescription_id (fk)

budgetdescription table : id, descriptionname

what tried far :

class="lang-php prettyprint-override"> $em = $this->getdoctrine()->getmanager(); $qb = $em->getrepository('mainbundle:budgetdata'); $qb = $em->createquerybuilder('d'); $dataquery = $qb->select('d, c') ->innerjoin('c.id', 'c', join::on, 'd.budgetdescription_id = c.id') ->getquery(); $dataquery = $dataquery->getarrayresult();

any thought how can sql query in dql ?

thank !

if have relation in budgetdataentity called budgetdescription attribute $budgetdescription, in budgetdatarepository :

public function myinnerjoin() { $qb = $this->createquerybuilder('f') ->select('f','g') ->innerjoin('f.budgetdescription', 'g'); homecoming $qb->getquery()->getarrayresult(); }

and in controller

$repository = $this->getdoctrine()->getmanager()->getrepository('acmebundle:budgetdata'); $result = $repository->myinnerjoin();

that guess

php symfony2 doctrine2

No comments:

Post a Comment