Skip to content

Loading…

DDC-1825: generate entities with traits #2483

Open
doctrinebot opened this Issue · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user lunetics:

When a trait with included setters and getters is used and generate entities is called, doctrine add another set of getters and setters to the "main" entity where the trait is used.

@doctrinebot

Comment created by lsv20:

/****
 * @ORM\Entity
 */
class Product {
    use Traits\Created;

    /****
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /****
     * Set name
     *
     * @param string $name
     * @return Attribute
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /****
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

}
Trait Created {
    /****
     * @var \DateTime $created
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    private $created;

    /****
     * @return \DateTime
     */
    public function getCreated()
    {
        return $this->created;
    }
}

Now when I run php app/console doctrine:generate:entities it copies everything from the trait and into the entity, so the entity now looks like

/****
 * @ORM\Entity
 */
class Product {
    use Traits\Created;

    /****
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /****
     * Set name
     *
     * @param string $name
     * @return Attribute
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /****
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /****
     * @var \DateTime $created
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    private $created;

    /****
     * @return \DateTime
     */
    public function getCreated()
    {
        return $this->created;
    }

}

And ofcourse invalidates the entity because it now has two methods of the getCreated and two of private $created

@doctrinebot

Comment created by wilgert:

Unfortunately I am also suffering from this bug. Is there anything I can do to help resolve it?

@doctrinebot

Comment created by ludwig.ruderstaller:

Same here - i think an easy fix would be to introduce an additional parameter, which if set, ignores all traits.

@beberlei beberlei was assigned by doctrinebot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.