在 Symfony 中使用 YAML 创建的关系(使用 Doctrine)不会填充到 MySQL 数据库中
我是 Symfony 的新手,尝试通过 build-model 然后 build-sql 创建数据库结构。
所有表都出现在数据库中,但是不会创建除简单一对多关系之外的关系。
例如,我有一个存储公司的表,它们可以是供应商或客户,我还有另一个存储客户/供应商关系的表。
Identifier:
actAs: [Timestampable]
tableName: identifier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Suppliers:
class: Identifier
local: customer_id
foreign: supplier_id
refClass: CustomerSupplier
foreignAlias: Customers
onDelete: CASCADE
Customers:
class: Identifier
local: supplier_id
foreign: customer_id
refClass: CustomerSupplier
foreignAlias: Suppliers
onDelete: CASCADE
CustomerSupplier:
actAs: [Timestampable]
tableName: customerSupplier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
customer_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
supplier_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
也不会创建一对一关系:
IdentifierExtCompany:
actAs: [Timestampable]
tableName: identifierExtCompany
columns:
identifier_id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Identifier:
local: identifier_id
foreign: id
onDelete: CASCADE
foreignType: one
type: one
当我运行 build-sql 生成的 sql 请求时,所有这些关系都不会出现在数据库中。
你能帮我检测一下我的 yaml 文件中有什么问题吗?提前致谢
I am new to Symfony, trying to create a database structure through build-model then build-sql.
All the tables appear in the database however relations other than simple one-to-many relations are not created.
For instance I have a table storing companies, they can be both suppliers or customers and I have another table storing the customer/supplier relationship.
Identifier:
actAs: [Timestampable]
tableName: identifier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Suppliers:
class: Identifier
local: customer_id
foreign: supplier_id
refClass: CustomerSupplier
foreignAlias: Customers
onDelete: CASCADE
Customers:
class: Identifier
local: supplier_id
foreign: customer_id
refClass: CustomerSupplier
foreignAlias: Suppliers
onDelete: CASCADE
CustomerSupplier:
actAs: [Timestampable]
tableName: customerSupplier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
customer_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
supplier_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
One-to-one relationships are not created either:
IdentifierExtCompany:
actAs: [Timestampable]
tableName: identifierExtCompany
columns:
identifier_id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Identifier:
local: identifier_id
foreign: id
onDelete: CASCADE
foreignType: one
type: one
All these relations don't appear in the database when I run the sql request generated by build-sql.
Could you help me to detect what is wrong in my yaml file? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您也必须为
CustomerSupplier
定义关系:尝试在关系中指定
class
属性并将其设置为Identifier
。希望这有帮助。
Seems like you have to define relations for
CustomerSupplier
too:Try to specify
class
attribute in relations and set it toIdentifier
.Hope this helps.