存储库类中调用的Symfony2 Entity方法


Symfony2 Entity method called in repository class

如何从存储库类中的实体类调用方法。我试过做这样的事,但没有成功。

class ProfileConnectionsListRepository extends EntityRepository
{
       public function connectionUserNames($userId)
       {
           $connections = $this->_em
               ->findOneBy(array('user1Id' => $userId))
               ->getUser2Id();
       }
}

因此,如果这是无效的,可以在不使用原始查询的情况下,以条令的方式执行类似的操作。

您可能需要先获取存储库。

$connections = $this->_em
   ->getRepository(UserEntity::class)
   ->findOneBy(array('user1Id' => $userId))
   ->getUser2Id();