4
votes

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

1
I don't think it's because of the self-referenced table per se, so much as the self-referenced column in the table. This doesn't seem to make sense to me, as if it is single-valued, then the only record it can refer to is itself. Are you sure that that is what you mean?Colin Fine
well, i'm not sure at all. But only the self-referencing tables crashes at building. If i remove them from the schema.yml the building goes fineAndreu Ramos

1 Answers

0
votes

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 }
[...]