在 Doctrine 2 ORM 中命名关系? [英] Naming a relation in Doctrine 2 ORM?
本文介绍了在 Doctrine 2 ORM 中命名关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 YAML 为多对一关系区域"设置外键名称(edit:不是属性本身的名称)?
How can i set the name of the foreign key (edit: not the name of the attribute itself) for the many-to-one relation "region" using YAML?
SWATestBundleEntityProvince:
type: entity
table: province
uniqueConstraints:
UNIQUE_PROVINCE_CODE:
columns: code
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
code:
type: integer
name:
type: string
length: 255
short_name:
type: string
length: 2
manyToOne:
region:
targetEntity: Region
inversedBy: provinces
推荐答案
看getCreateConstraintSQL 方法在 AbstractPlatform 类中 查看外键名称是如何选择的(第 1088 行).
Look at the getCreateConstraintSQL method in the AbstractPlatform class to see how the name of the foreign key is chosen (line 1088).
它直接取自约束名称.影响约束名称将影响外键名称.
It is taken directly from the constraint name. Influencing constraint name will influence the foreign key name.
作为一种解决方法,您可以删除约束并在 中使用新名称重新创建它学说迁移.
As a workaround you could drop the constraint and re-create it with a new name in a doctrine migration.
这篇关于在 Doctrine 2 ORM 中命名关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文