我们首先描述一下我的情况。我正在使用Symfony2,并且我的实体之间存在关系问题。与一个实体共享同一个OneToMany关系的两个属性Symfony2
我有两个链接在一起的实体。这两个实体分别是AssociationQuestion
和AssociationPossibleAnswer
。我目前正在创建一个问卷软件,其中一个将不得不在右边左边链接一个可能的答案,另外一个可能的答案,如下面的例子:
目前,我打算有两个属性是类AssociationQuestion
中的数组,该数组可以容纳多个AssociationPossibleAnswer
对象。第一个数组包含左侧可能的答案,第二个数组包含右侧可能的答案。
因此,对我来说,它看起来像我将有两个一对多关系,AssociationQuestion
AssociationQuestion:
oneToMany:
possibleAnswersLeft:
targetEntity: AssociationPossibleAnswer
mappedBy: associationQuestion
possibleAnswersRight:
targetEntity: AssociationPossibleAnswer
mappedBy: associationQuestion
然后,在AssociationPossibleAnswer
,我将有一个多对一的关系:
AssociationPossibleAnswer:
manyToOne:
associationQuestion:
targetEntity: AssociationQuestion
的问题是,我尝试验证我的学说时出现以下错误。看来你不能链接到一个如我所希望做的两个实体...
* The field AssociationQuestion#possibleAnswersLeft is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity AssociationPossibleAnswer#associationQuestion does not contain the required 'inversedBy=possibleAnswersLeft' attribute.
* The field AssociationQuestion#possibleAnswersRight is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity AssociationPossibleAnswer#associationQuestion does not contain the required 'inversedBy=possibleAnswersRight' attribute.
我想知道如果这是我的设置我的两个实体之间关系的正确方法。 是否有可能有两个属性指向一个实体,而实体不知道它指向哪个属性。