How can I specify the setter name with the entites who's generated with Doctrine2 in Symfony2?

StackOverflow https://stackoverflow.com/questions/7304742

  •  25-10-2019
  •  | 
  •  

Question

I have an event entity and a user entity with an unidirectionnal many to many relation between them. When, I created the event entity with the generator (doctrine:generate:entites) the getteur called getParticipants and the setter called AddUser.

I guess that the setter is composed by the namespace of the target entity. There is an option who allows to change the setter name in my orm settings?

Event.orm.yml

participants:
targetEntity: RocketLab\UserBundle\Entity\User
joinTable:
    name: event_user
    joinColumns:
        user_id:
           referencedColumnName: id
           onDelete: CASCADE
    inverseJoinColumns:
        event_id:
            onDelete: CASCADE
            referencedColumnName: id

Entity/Event.php

/**
 * Add participants
 *
 * @param RocketLab\UserBundle\Entity\User $participants
 */
public function addUser(\RocketLab\UserBundle\Entity\User $participants)
{
    $this->participants[] = $participants;
}

/**
 * Get participants
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getParticipants()
{
    return $this->participants;
}

Thanks in advance.

Was it helpful?

Solution

You cannot influence the names of generated getter and setter methods. You can just change them afterwards though, as they serve no architectural purpose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top