Traits - property conflict with parent class

依然范特西╮ 提交于 2019-12-01 03:05:31

No, it's not yet possible to rewrite a mapped property by using a Trait.

Also, a possible alternative is to use multiple abstract entity classes, and extend your child entities depending on your need.

i.e.

<?php

use FOS\UserBundle\Model\User as BaseUser;

abstract class AbstractStrategyNoneEntity extends BaseUser
{
    /**
     * @ORM\Column(type="string", length=255)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    protected $id;
}

abstract class AbstractStrategyAutoEntity extends BaseUser
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     */
    protected $id;
}

And extend one of them in your child entities.

/**
* @ORM\Entity
*/
class Child extends AbstractStrategyNoneEntity 
{
    // Inherited mapping
}

Hopes this answers your question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!