如何使用 Propel ORM 在 Symfony 中构建自引用表
我在尝试使用 Propel ORM 从 symfony 项目中的现有数据库构建模型时遇到错误。
错误是这样的:
build-propel.xml:474:20:外键a_table_on_my_schema_FK_1表示的1:1关系是双向定义的; Propel 目前不支持此功能(如果您必须同时具有两个外键约束,请考虑使用自定义 SQL 文件添加此约束。)
schema.yml 文件确实很广泛,但导致错误的表的描述(第一个不正确)创建)是这样的:
self_referenced_table:
_attributes: { phpName: SelfReferencedTable }
[...]
JERARQUIC_CODE: { phpName: JerarquicCode, type: INTEGER, size: '8', required: false, foreignTable: self_referenced_table, foreignReference: JERARQUIC_CODE, onDelete: RESTRICT, onUpdate: RESTRICT }
[...]
我认为这个错误是因为自引用表。
我需要在许多元素之间实现一种混乱的关系,因此这个实现是一个很好的方法。但这给我带来了施工上的问题。
你能给我一些线索吗?有人遇到这个错误吗?你会怎么办?
谢谢你!! :D
I have an error trying to build a model from an existing database in a symfony project using the Propel ORM.
The error is this:
build-propel.xml:474:20: The 1:1 relationship expressed by foreign key a_table_on_my_schema_FK_1 is defined in both directions; Propel does not currently support this (if you must have both foreign key constraints, consider adding this constraint with a custom SQL file.)
the schema.yml file is really extensive but the description of the table that causes the error (the first not correctly created) is like this:
self_referenced_table:
_attributes: { phpName: SelfReferencedTable }
[...]
JERARQUIC_CODE: { phpName: JerarquicCode, type: INTEGER, size: '8', required: false, foreignTable: self_referenced_table, foreignReference: JERARQUIC_CODE, onDelete: RESTRICT, onUpdate: RESTRICT }
[...]
I think this error is because of the self referenced table.
I need to implement a jerarquic relation between many elements so this implementation is a good way to do it. But causes me this problem on construction.
Can you give me some clues? have someone had this error? what would you do?
thank you!! :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决:正如 @Colin Fine 所说,这不是自引用表错误。错误发生在源数据库上。我从 mysql 上的现有数据库生成了 schema.yml。错误就在那里:引用的目标属性不是表的标识符,而是引用属性本身。因此,生成的 schema.yml 包含错误的定义。我想我解释得不够好:
self_referenced_table 是这样的:
_attributes: { phpName: SelfReferencedTable }
[...]
JERARQUIC_CODE: { phpName: JerarquicCode, 类型: INTEGER, 大小: '8', 必需: false,foreignTable: self_referenced_table,foreignReference: JERARQUIC_CODE, onDelete: RESTRICT, onUpdate: RESTRICT }
[...]
self_referenced_table 应该是:
_attributes: { phpName: SelfReferencedTable }
[...]
JERARQUIC_CODE:{ phpName:JerarquicCode,类型:INTEGER,大小:'8',必需:false,foreignTable:self_referenced_table,foreignReference:TABLE_CODE,onDelete:RESTRICT,onUpdate:RESTRICT }
[...]
Solved: It was not a self referencing table error, as said by @Colin Fine. The error was on the source database. I generated the schema.yml from an existing database on mysql. The error was there: the target attribute of the reference was not the identifier of the table, was the reference attribute itself. So, the generated schema.yml contained wrong definitions. I think i havn't explained well enough:
self_referenced_table was that:
_attributes: { phpName: SelfReferencedTable }
[...]
JERARQUIC_CODE: { phpName: JerarquicCode, type: INTEGER, size: '8', required: false, foreignTable: self_referenced_table, foreignReference: JERARQUIC_CODE, onDelete: RESTRICT, onUpdate: RESTRICT }
[...]
self_referenced_table should be:
_attributes: { phpName: SelfReferencedTable }
[...]
JERARQUIC_CODE: { phpName: JerarquicCode, type: INTEGER, size: '8', required: false, foreignTable: self_referenced_table, foreignReference: TABLE_CODE, onDelete: RESTRICT, onUpdate: RESTRICT }
[...]