简体   繁体   中英

How can I write a DQL for these entities?

I have entities seen as DB screenshot:

You can see the screenshot here-> http://imageshack.us/photo/my-images/830/asdsasda.jpg/

I want to bring an object array of TnModuleItem by giving a TnRegion parameter.

How can i write in DQL to bring this query.

Edit: I want to write a model like this:

public function get_module_items_by_region_id($region_id){
// code comes here
return $tnModuleItemsObj //TnModuleItemsObject
}

And if you try something like:

 <?php
 public function get_module_items_by_region_id($region_id){
     $query = $em->createQuery('SELECT i FROM \namespace\TnRegionModuleItem as i WHERE i.regionId = :region_id');
     $query->setParameter('region_id', $region_id)

     return $query->getResult()
 }     

 ?>

Offcourse you should get your entitymanager somewhere from and put in the variable $em, in my case I use the Bisna 'glue' for Zend Framework and I retrieve it by the Zend_Registry but that could be different in your case.

With the result value you can foreach your module items and every element is a tnModuleItem object.

Good luck!

OK. I solved problem with this:

            $query = $this->em->createQuery('SELECT rmi, mi FROM TnRegionModuleItem rmi JOIN rmi.moduleItem mi JOIN rmi.pageRegion pr JOIN pr.region r WHERE r.id = :regionid');

must select a root entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM