有没有办法在教义中添加外键约束?这是我在Symfony 3.3中对实体的配置。原则:方案:验证命令给了我一个答案,例如"表'关税'上没有名称为'产品'的列"
RgApiBundleEntityTariff:
fields:
price:
type: float
column: price
manyToOne:
product:
targetEntity: Product
inversedBy: tariffs
timeunit:
targetEntity: Timeunit
inversedBy: tariffs
uniqueConstraints:
no_double_tariff_idx:
columns:
- product
- timeunit
您需要引用列的名称(而不是教义使用的关系的名称)。默认情况下,原则将使用 _id
作为关系名称的后缀,但您可以配置连接列的确切名称,如以下示例配置所示:
'YourEntityProductVariant':
manyToOne:
image:
targetEntity: 'YourEntityProductImage'
joinColumn:
name: '`image_id`'
referencedColumnname: 'id'
nullable: false
options:
unique: false
color:
targetEntity: 'YourEntityProductColor'
joinColumn:
name: '`color_id`'
referencedColumnname: 'id'
# [..]
uniqueConstraints:
only_one_image_of_same_product_color_idx:
columns:
- 'image_id'
- 'color_id'