Symfony2访问存储库查询php中的外键结果

时间:2015-08-26 09:03:11

标签: php symfony doctrine

使用find all repository方法时,如何访问查询结果中的foriegn键。特别是Jobs_id外键,它被提取到jobs对象中。

$entities = $em->getRepository('btBundle:workHours')->findAll();
    $em = $this->getDoctrine()->getManager();

using  foreach ($entities as $test) {
        $Id=$test->getId();  //Works fine
        $jobs=$test-getJobs(); // retrieves Jobs object.
        $jobs->getId(); // Error: Call to a member function getid() on a non-object   

}

正如它所说的不是一个对象,我试图通过尝试像

之类的东西来对待它
$jobs[0];
$jobs['id'];
  

给出错误错误:不能使用类型的对象   代理..... \ Entity \ Jobs as array

这是$ jobs

的1个实例的转储
Jobs {#709 ▼
  #clients: Clients {#710 ▶}
  #company: Company {#638 ▶}
  #scopes: PersistentCollection {#711 ▶}
  #workHours: PersistentCollection {#713 ▶}
  #userDetails: PersistentCollection {#715 ▶}
  -id: 101
  -description: "Test Job"
  -jobNumber: "7844.00"
  -task: null
  -currencies: "USD"
  -active: 1
}

0 个答案:

没有答案