使用一种方法从一个实体获取多个数据

时间:2016-07-19 11:18:17

标签: symfony orm doctrine-orm

如何从实体数据行获取多个数据

 public function findByUser1Id($userId)
       {
           $connections = $this->_em
               ->getRepository('AppBundle:ConnectionsList')
               ->findBy(array('user1Id' => $userId));

           foreach($connections as $con)
           {
               $user = $this->_em
                   ->getRepository('AppBundle\Entity\User')
                   ->findOneBy(array('id' => $con->getUser2Id()));

               var_dump($user->getFirstname());
               var_dump($user->getLastname());
               var_dump($user->getEmail());
               var_dump($user->getId());
               die;
           }
       } 

我需要一些方法来在一行中获取数据:

$user->get(array('firstname', 'lastname', 'email' ...))

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,但无法在一行中获取所有数据

代码在这里:

!ENTRY org.eclipse.osgi 4 0 2016-07-19 14:05:02.890
!MESSAGE Application error
!STACK 1
java.lang.NoClassDefFoundError: org/w3c/dom/Node
    at org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl.createXMLLoad(XMIResourceImpl.java:55)
    at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.createXMLLoad(XMLResourceImpl.java:166)
    ...
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node cannot be found by org.eclipse.emf.ecore.xmi_2.10.2.v20150123-0348
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:455)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 31 more