0

How can I call method from entity class in repository class. I had tried to do something like this, but no success.

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

so if this is invalid can do something like that on doctrine way without using raw queries.

3
  • 1
    Check the result of findOneBy. It should be your entity, but maybe also NULL if no user with the given ID was found. Commented Jul 19, 2016 at 9:38
  • What is result of $this->_em->findOneBy(array('user1Id' => $userId));? Commented Jul 19, 2016 at 10:09
  • What do you mean by no success? What does $this->_em ->findOneBy(array('user1Id' => $userId)) give you? Commented Jul 19, 2016 at 10:09

1 Answer 1

2

You might need to get repository first.

$connections = $this->_em
   ->getRepository(UserEntity::class)
   ->findOneBy(array('user1Id' => $userId))
   ->getUser2Id();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks you mate, you save my nerves :)
Been there. Glad to help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.