我們首先描述一下我的情況。我正在使用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.
我想知道如果這是我的設置我的兩個實體之間關係的正確方法。 是否有可能有兩個屬性指向一個實體,而實體不知道它指向哪個屬性。