1
votes

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:

  1. why is field "id" not set correctly (it remains null)?
  2. Is the manyToOne-correlation made correctly for a composite primary key? Or must i use "joinColumns" instead of "joinColumn"? And when i have to use "joinColumns" can you give me a short example, how the orm.yml-configuration should look like? I couldn't find the correct answer in google until now.

Thanxs for your help.

2

2 Answers

1
votes

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.

0
votes

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