Symfony / Doctrine: add annotiation to Attribute defined in 'MappedSuperclass'

笑着哭i 提交于 2019-12-14 03:18:07

问题


Edit: I learned, that there's an annotiation missing for my subclass ('here it's just an ID', thx to GreenLeaf). My actual problem now is, that I don't know, how to override this, I can't get it to work.


Original:

I just migrated a Symfony 2.0 Application to Symfony 2.2 and get an 'invalid entities'-information in the dev-profiler, regarding an unidirectional one-to-many-association. When using the console with

php console doctrine:schema:validate

I receive 2 Messages:

* The association \Entity\Watched#reference refers to the inverse side field \Entity\Reference#id which is not defined as association.
* The association \Entity\Watched#reference refers to the inverse side field \Entity\Reference#id which does not exist.

I think, that this is wrong, because 'id' is defined in a superclass. The App stills runs fine on the old DB (created with Symfony 2.0). This are my classes (simplified):

Code: Select all

/**
 * @ORM\MappedSuperclass
 * @ORM\HasLifecycleCallbacks
 */
abstract class SuperclassAbstract {
   /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\GeneratedValue(strategy="AUTO")
    */
   protected $id = "";

   // some fields more...
}

/**
 * @ORM\Entity
 * @ORM\Table(name="watched")
 */
class Watched extends SuperclassAbstract {
   /**
    * @ORM\ManyToOne(targetEntity="Reference", inversedBy="id")
    * @ORM\JoinColumn(name="reference_id", referencedColumnName="id")
    */
   protected $reference;

   // some fields more...
}

/**
 * @ORM\Entity
 * @ORM\Table(name="reference")
 */
class Reference extends SuperclassAbstract {
   // some fields more...
}

回答1:


I must not see doctrine as an relational DB.... thanks!

I add a list to Reference to handle the other side of the association.



来源:https://stackoverflow.com/questions/15827368/symfony-doctrine-add-annotiation-to-attribute-defined-in-mappedsuperclass

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