早上好,
我在创建表格/加载固定装置时遇到了一些问题。
(symfony 1.4.6 与捆绑的 Doctrine 1.2.3(?))
表格(简化):
Horseman:
tableName: Horseman
actAs: { Timestampable: ~ }
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
name: { type: string(100), notnull: true }
Stable:
tableName: Stable
actAs: { Timestampable: ~ }
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
info: { type: clob }
id_owner: { type: integer(4), unsigned: true }
relations:
Horseman: { local: id_owner, foreign: id }
Horses:
tableName: Horses
actAs: { Timestampable: ~ }
columns:
id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
name: { type: string(100), notnull: true }
id_owner: { type: integer(4), unsigned: true }
id_stable: { type: integer(4), unsigned: true }
relations:
Horseman: { local: id_owner, foreign: id }
Stable: { local: id_stable, foreign: id }
“骑士”没有任何依赖
“马厩”有一个“骑士”
“Horses”有一个“Horseman”和一个“Stable”
固定装置:
Horseman:
Hector:
name: Hector
Stable:
StableA:
info: Lorem Ipsum Dolor Sit Amet
id_owner: Hector
Horses:
Ed:
name: Ed
id_owner: Hector
id_stable: StableA
插入夹具时:
$ php symfony doctrine:build --all --and-load
我违反了约束:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`issuetracker/Stable`, CONSTRAINT `Stable_id_owner_Horseman_id` FOREIGN KEY (`id_owner`) REFERENCES `Horseman` (`id`))
插入“Horseman”条目没有问题。
手动插入其他两个条目也不成问题:
INSERT INTO Stable (id,info,id_owner,created_at,updated_at) VALUES (null,"foo",1,NOW(),NOW())
INSERT INTO Horses (id,name,id_owner,id_stable,created_at,updated_at) VALUES (null,"foo",1,1,NOW(),NOW())
(symfony 是否将创建的插入语句保存在某处?)
如果我做对了,Doctrine 应该自己负责插入订单(?)因为无论如何我给出了正确的订单,这不应该是问题..
希望我只是没有看到或没有得到一件小事,你们中的一个好人能告诉我为什么我会违反约束和/或如何解决它,非常拜托..
谢谢。
最佳答案
像这样尝试:
Horseman:
Hector:
name: Hector
Stable:
StableA:
info: Lorem Ipsum Dolor Sit Amet
Horseman: Hector
Horses:
Ed:
name: Ed
Horseman: Hector
Stable: StableA
您不想使用相关对象的 ID,而是使用相关对象。这就是为什么您应该使用关系名称而不是字段名称。
关于php - Doctrine (symfony) YAML schema/fixture 约束问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3841033/