Symfony/Doctrine: Traits and Annotations

Viewed 6196

I have an entity Test which will get its properties (and basic methods) from traits:

class Test {
   use Trait_title;
}

trait Trait_title{
    /**
     * @ORM\Column(type="string", length=255, nullable=false)
     */
    private $title;
}

That works correctly. But when I try to put the annotations in the Test Class in front of the use statement, partially or complete they are just ignored by symfony when I try to update the schema:

class Test {
    /**
     * @ORM\Column(type="string", length=255, nullable=false) //will be ignored...
     */
   use Trait_title;
}

trait Trait_title {
    private $title;
}

The purpose of this is to move defaults for doctrine annotations into the trait, but to be allowed to set some custom annotations like nullable per entity as well.

1 Answers
Related