首先描述一下我的情况。我正在使用 Symfony2,但我的实体之间的关系存在问题。
我有两个链接在一起的实体。这两个实体是AssociationQuestion
and AssociationPossibleAnswer
。我目前正在创建一个调查问卷软件,其中必须将左侧的一个可能答案链接到右侧的另一个可能答案,例如以下示例:
目前,我计划在类中拥有两个数组属性AssociationQuestion
那将容纳许多AssociationPossibleAnswer
对象。第一个数组将包含左侧的可能答案,第二个数组将包含右侧的可能答案。
因此,对我来说,看起来我会有两个 oneToMany 关系AssociationQuestion
AssociationQuestion:
oneToMany:
possibleAnswersLeft:
targetEntity: AssociationPossibleAnswer
mappedBy: associationQuestion
possibleAnswersRight:
targetEntity: AssociationPossibleAnswer
mappedBy: associationQuestion
然后,在AssociationPossibleAnswer
,我会有一个 ManyToOne 关系:
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.
我想知道这是否是设置两个实体之间关系的正确方法。是否有可能有两个属性指向一个实体,而实体却不知道它是从哪个属性指向的。