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
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top