Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.2
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
      None
    • Environment:
      php 5.4.3, symfony2.1-dev
      php 5.5.12, symfony 2.5

      Description

      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.

        Activity

        Hide
        Martin Aarhof added a comment - - edited
        /**
         * @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

        Show
        Martin Aarhof added a comment - - edited /** * @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

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Matthias Breddin
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: