DDC-1579: MappedSuperClass and inheritance problem with console generate:entities command #1984

Closed
opened 2026-01-22 13:36:00 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 5, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user smoya:

I have two classes.

One extends from another. I'm using the annotation @MappedSuperclass
and operates correctly, but when he did the entities generation
through the command console, doctrine adds the property and the
methods of the "father" class in the subclass.

This is a bug of the command console?

Really you should not copy them if you do not extend them. When you
run the update of the database schema, i must delete these fields and
methods added to obtain the desired result.

What happens?

Im usign Symfony 2.

Thanks!!!!

Code:

Father class:

/**********************************************************************

/****

  • @ORM\MappedSuperclass
    */
    abstract class ConfigBase
    {

    /****

    • @ORM\Column(name="enabled", type="boolean")
      */
      protected $enabled;

    /****

    • Set enabled
      *
    • @param boolean $enabled
      */
      public function setEnabled($enabled)
      {
      $this->enabled = $enabled;
      }

    /****

    • Get enabled
      *
    • @return boolean
      */
      public function getEnabled()
      {
      return $this->enabled;
      }

}

/**********************************************************************

SubClass

/**********************************************************************

/****

  • @ORM\Entity
    *
    /
    class UserConfig extends ConfigBase
    {
    /
    ***

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

    /****

    • Get id
      *
    • @return integer
      */
      public function getId()
      {
      return $this->id;
      }

/*******************************************_/
/* Auto generated and non desired values **/
/*************************************************
/
/
_*
* @var boolean $enabled
*/
private $enabled;

/****
 * Set enabled
 *
 * @param boolean $enabled
 */
public function setEnabled($enabled)
{
    $this->enabled = $enabled;
}

/****
 * Get enabled
 *
 * @return boolean
 */
public function getEnabled()
{
    return $this->enabled;
} 
Originally created by @doctrinebot on GitHub (Jan 5, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user smoya: I have two classes. One extends from another. I'm using the annotation @MappedSuperclass and operates correctly, but when he did the entities generation through the command console, doctrine adds the property and the methods of the "father" class in the subclass. This is a bug of the command console? Really you should not copy them if you do not extend them. When you run the update of the database schema, i must delete these fields and methods added to obtain the desired result. What happens? Im usign Symfony 2. Thanks!!!! Code: Father class: /********************************************************************** /**** - @ORM\MappedSuperclass */ abstract class ConfigBase { /**** - @ORM\Column(name="enabled", type="boolean") */ protected $enabled; /**** - Set enabled * - @param boolean $enabled */ public function setEnabled($enabled) { $this->enabled = $enabled; } /**** - Get enabled * - @return boolean */ public function getEnabled() { return $this->enabled; } } /********************************************************************** SubClass /********************************************************************** /**** - @ORM\Entity * _/ class UserConfig extends ConfigBase { /_*** - @var integer $id * - @ORM\Column(name="id", type="integer") - @ORM\Id - @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /**** - Get id * - @return integer */ public function getId() { return $this->id; } /***********************************************_**/ /_\* Auto generated and non desired values **/ /*************************************************_/ /**_* \* @var boolean $enabled */ private $enabled; ``` /**** * Set enabled * * @param boolean $enabled */ public function setEnabled($enabled) { $this->enabled = $enabled; } /**** * Get enabled * * @return boolean */ public function getEnabled() { return $this->enabled; } ```
admin added the Bug label 2026-01-22 13:36:00 +01:00
admin closed this issue 2026-01-22 13:36:03 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2012):

@doctrinebot commented on GitHub (Jan 5, 2012): - depends on [DDC-1590: Fix Inheritance in Code-Generation](http://www.doctrine-project.org/jira/browse/DDC-1590)
Author
Owner

@doctrinebot commented on GitHub (Jan 9, 2012):

Comment created by @beberlei:

It is a known problem that will be fixed in 2.3 hopefully.

@doctrinebot commented on GitHub (Jan 9, 2012): Comment created by @beberlei: It is a known problem that will be fixed in 2.3 hopefully.
Author
Owner

@doctrinebot commented on GitHub (Jan 9, 2012):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Jan 9, 2012): Issue was closed with resolution "Duplicate"
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2012):

Comment created by johan:

I just noticed that this is only an issue if the member has a protected scope in the mapped super class, it works fine for private members.

@doctrinebot commented on GitHub (Jul 3, 2012): Comment created by johan: I just noticed that this is only an issue if the member has a protected scope in the mapped super class, it works fine for private members.
Author
Owner

@doctrinebot commented on GitHub (Dec 10, 2012):

Comment created by lukxde:

As of Doctrine 2.3.0, Symfony 2.1.3, this behaviour is still reproducable.
Mr. Ehlers is correct; generation will work correctly when the super class' properties are set to private scope. However, in that case the Proxy Object's lazy loading can't set the properties in question.

@doctrinebot commented on GitHub (Dec 10, 2012): Comment created by lukxde: As of Doctrine 2.3.0, Symfony 2.1.3, this behaviour is still reproducable. Mr. Ehlers is correct; generation will work correctly when the super class' properties are set to private scope. However, in that case the Proxy Object's lazy loading can't set the properties in question.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1984