Symfony 在学说中对外键的独特限制
有没有办法在原则中添加外键约束?这是我对Symfony 3.3中实体的配置。 条令:方案:验证命令给出的回答类似于“在“关税”表中没有名为“产品”的列”Symfony 在学说中对外键的独特限制,symfony,doctrine-orm,Symfony,Doctrine Orm,有没有办法在原则中添加外键约束?这是我对Symfony 3.3中实体的配置。 条令:方案:验证命令给出的回答类似于“在“关税”表中没有名为“产品”的列” 您需要引用列的名称(而不是原则使用的关系的名称)。默认情况下,条令将用\u id作为关系名称的后缀,但您可以配置连接列的确切名称,如以下配置示例所示: 'Your\Entity\ProductVariant': manyToOne: image: targetEntity: 'Your\Entity\Product\Im
您需要引用列的名称(而不是原则使用的关系的名称)。默认情况下,条令将用
\u id
作为关系名称的后缀,但您可以配置连接列的确切名称,如以下配置示例所示:
'Your\Entity\ProductVariant':
manyToOne:
image:
targetEntity: 'Your\Entity\Product\Image'
joinColumn:
name: '`image_id`'
referencedColumnname: 'id'
nullable: false
options:
unique: false
color:
targetEntity: 'Your\Entity\Product\Color'
joinColumn:
name: '`color_id`'
referencedColumnname: 'id'
# [..]
uniqueConstraints:
only_one_image_of_same_product_color_idx:
columns:
- 'image_id'
- 'color_id'
您可以尝试使用注释,它更清晰、更简单。谢谢您的回答。那么我将如何通过注释来实现这一点呢?您可以尝试使用
列数组中的product\u id
和timeunit\u id
吗?非常感谢。我马上就做了你的建议,很管用。
'Your\Entity\ProductVariant':
manyToOne:
image:
targetEntity: 'Your\Entity\Product\Image'
joinColumn:
name: '`image_id`'
referencedColumnname: 'id'
nullable: false
options:
unique: false
color:
targetEntity: 'Your\Entity\Product\Color'
joinColumn:
name: '`color_id`'
referencedColumnname: 'id'
# [..]
uniqueConstraints:
only_one_image_of_same_product_color_idx:
columns:
- 'image_id'
- 'color_id'