php - Synfony 3 doctrine show content from relationship on repo -


i have symfony entities srvrsservers , ncbackupevents:

  • ncbrtbundle:srvrsservers (id, name, description, etc)

relationship code:

 /**  * 1 srvrsservers has many ncbackupevents.  * @orm\onetomany(targetentity="ncbackupevents", mappedby="srvrsservers")  */ private $ncbackupevents;  public function __construct() {     $this->ncbackupevents = new arraycollection(); }  
  • ncbrtbundle:ncbackupevents (id, date, status, etc)

this on ncbackupevents:

 /**  * @var \srvrsservers  *  * @orm\manytoone(targetentity="srvrsservers")  * @orm\joincolumns({  *   @orm\joincolumn(name="srvrs_servers_id", referencedcolumnname="id")  * })  */ private $srvrsservers; 

the relationship 1 many srvrsservers ncbackupevents. on repo of ncbackupevents able pull information itself. works , think srvrsservers object get's pulled, not 100% sure , not know how access it:

class ncbackupeventsrepository extends \doctrine\orm\entityrepository {     public function findbyserverbackup($parameters)     {         $dql = 'select n ncbrtbundle:ncbackupevents n              n.backupmethod :backupmethod             , n.backuptype :backup_type              , n.log :log';         $query = $this->getentitymanager()                 ->createquery($dql)                 ->setparameter('backupmethod',                     '%'.$parameters['backupmethod'].'%')                 ->setparameter('backup_type',                     '%'.$parameters['backup_type'].'%')                 ->setparameter('log', '%'.$parameters['log'].'%');        try {             return $query->getresult();         } catch (\doctrine\orm\noresultexception $e) {             return null;        }     } } 

how can query controller using srvrsservers->name field instace? have tried many things , nothing seems work. should simple, not understand how done. have tried follow official docs , can not work reason. can point me way this? please keep present newbie.

edit: sample controller.

 /**  * @route("/")  */ public function indexaction() {     $paramaters = array('backupmethod' => 't-py',         'backup_type' => '', 'log' => 'fuc');     $em = $this->getdoctrine()             ->getrepository('ncbrtbundle:ncbackupevents')             ->findbyserverbackup($paramaters);     foreach($em $value){         print_r(gettype($value));         print_r($value->getsrvrsservers()->getname());     }     return $this->render('ncbrtbundle:default:index.html.twig'); } 

edit2: wan include server name on $paramaters variable srvrsservers entity


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -