2

I have 3 "main" entities : TypeA and TypeB linked to User by a ManyToOne relation.

I have 2 "secondary" entities : UserTypeA and UserTypeB, which contain the attributes of the ManyToOne relations (for example, the comment a user has assigned to a product of type A). These two entities and their repository are similar (except that one is linked to TypeA and the other to TypeB).

Here is a part of my code :

public function typea_commentAction(TypeA $typea)
{
   $user = $this->getUser();
   $userTypeA = $this->getDoctrine()
                      ->getManager()
                      ->getRepository('GamUserBundle:UserTypeA')
                      ->getComment($user, $typea);

   //...
}

public function typeb_commentAction(TypeB $typeb)
{
   $user = $this->getUser();
   $userTypeB = $this->getDoctrine()
                      ->getManager()
                      ->getRepository('GamUserBundle:UserTypeB')
                      ->getComment($user, $typeb);

   //...
}

As you can see, I need to duplicate each action to make them work with each entity. Is there any way to combine these actions ? Same question about the secondary entities and their repositories.

Thanks.

1 Answer 1

3

Create a service class that performs the logic and takes say, the user type as a parameter.

Sign up to request clarification or add additional context in comments.

Comments

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.