Reputation: 98
I'm writing at the moment a fixture loader command, where i generate a mysql-database with orm.yml-files and loading database fixture afterwards. At the moment the loader command is working fine for tables with a simple primary key. But now I have a table, which consists of a composited primary key (of three columns). Two Columns ("id" and "language") are foreign keys to another tables (with a 1:n relationship).
I'm getting this error message, when I make the fixture loader command call:
Message: An exception occurred while executing 'INSERT INTO xyzInt (id, language, name, text, update, userID, complete) VALUES (?, ?, ?, ?, ?, ?, ?)' with params [null, "com", "peter", "text", "2017-03-06 18:00:00", 1, 0]:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update, userID, complete) VALUES (NULL, 'com', 'peter', 'text', '2017-03-' at line 1
And my xyzInt.orm.yml looks like this:
Entity\Xyzint:
type: entity
table: xyzInt
id:
id: { type: integer, options: { default: 0, unsigned: true }, generator: { strategy: NONE } }
language: { type: string, length: 2, options: { default: '' }, generator: { strategy: NONE } }
name: { type: string, length: 30, options: { default: '' }, generator: { strategy: NONE } }
fields:
...
manyToOne:
Abc:
targetEntity: Abc
inversedBy: Xyzint
joinColumn:
name: id
referencedColumnName: abcID
And now i've got two questions:
Thanxs for your help.
Upvotes: 1
Views: 258
Reputation: 98
I solved my problem with following solution: In the table xyzInt i've added a new column, which is used as THE NEW simple primary key now. The value of the new column is a combination of id, language and name. And the columns id, language and name are now normal columns, which are indexed.
Upvotes: 1
Reputation: 2885
I'm not confortable with Yaml but I think you should set your generation strategy to auto. Something like this :
id: { type: integer, options: { default: 0, unsigned: true }, generator: { strategy: AUTO } }
Change strategy: NONE
to strategy: AUTO
Here is the doc for YAML config : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/yaml-mapping.html
Upvotes: 0