Relations created with YAML in Symfony (with Doctrine) are not populated in MySQL database
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:开发者_如何学C 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
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.
Seems like you have to define relations for CustomerSupplier
too:
relations:
IdentifierAlias:
class: Identifier
local: identifier_id
onDelete: CASCADE
SupplierAlias:
class: Supplier
local: supplier_id
onDelete: CASCADE
One-to-one relationships are not created either
Try to specify class
attribute in relations and set it to Identifier
.
Hope this helps.
精彩评论