S
S
Strate2012-08-12 16:14:16
symfony
Strate, 2012-08-12 16:14:16

Entity inheritance via Superclass in Doctrine 2, why are fields copied to descendants?

Good afternoon everyone!
Understanding inheritance in Doctrine 2 as described here.
I create a class:

use Doctrine\ORM\Mapping as ORM;<br><br>
/**<br>
 *<br>
 * @ORM\MappedSuperclass<br>
 */<br>
abstract class AbstractEntity<br>
{<br>
    /**<br>
     * @var User<br>
     * @ORM\ManyToOne(targetEntity="User")<br>
     * @ORM\JoinColumn(name="user_created_id", referencedColumnName="id")<br>
     */<br>
    protected $userCreated;<br><br>
    /**<br>
     * Set userCreated<br>
     *<br>
     * @param User $userCreated<br>
     * @return AbstractEntity<br>
     */<br>
    public function setUserCreated(User $userCreated = null)<br>
    {<br>
        $this->userCreated = $userCreated;<br>
        return $this;<br>
    }<br><br>
    /**<br>
     * Get userCreated<br>
     *<br>
     * @return User<br>
     */<br>
    public function getUserCreated()<br>
    {<br>
        return $this->userCreated;<br>
    }<br>
}<br>

I create an heir:
/**<br>
 * @ORM\Entity<br>
 */<br>
class Record extends AbstractEntity {<br>
    /**<br>
     * @ORM\Id<br>
     * @ORM\Column(name="id", type="integer")<br>
     * @var integer<br>
     */<br>
    protected $id;<br>
}<br>

And after that in the console I execute
php app/console doctrine:generate:entities NAMESPACE

What's the problem: the doctrine generator copies the $userCreated field along with the getters and setters to the child. How to avoid it? In the same FOSUsersBundle, inheritance rolls, though there is a config in xml, and not in annotations like mine, but this can’t be a problem, right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
m_z, 2012-09-10
@Strate

Execution doctrine:generate:entitiesshould be generally avoided. This command is only used to start and allows you to convert an existing database structure into entities. In the future, entities need to be ruled only by hands.

M
MuXaJIbI4, 2012-09-10
@MuXaJIbI4

I didn’t check it myself ... but maybe because they have an abstract class User?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question