1

I have a some problem with my symfony project.
I have a MySQL database with InnoDB tables.
I try to create simple tree-menu:

schema.yml

Menu:
  actAs:
    Timestampable:
      created:
        disabled: true
      updated:
        disabled: true
  columns:
    id: { type: integer, autoincrement: true, notnull: true, primary: true }
    name: { type: string(255), notnull: true }
    parent: { type: integer, notnull: false }
  relations:
    Parent:
      alias: parentItem
      foreignAlias: childrens
      class: Menu
      local: parent
      foreign: id
      type: many-to-one
      onDelete: CASCADE

After creating elements in backend I execute data:dump and get this code

fixture:

Menu:
  Menu_1:
    name: 'Parent'
  Menu_2:
    parentItem: Menu_1
    name: 'Children'

If I try to run, I have lost the relations between the items

I do not understand what's wrong.

Edit:

Before:

| id | name     | parent |
| 1  | Parent   | NULL   |
| 2  | Children | 1      |

After

| id | name     | parent |
| 1  | Parent   | NULL   |
| 2  | Children | 0      |
j0k
  • 22,600
  • 28
  • 79
  • 90
Dmitry
  • 551
  • 6
  • 19

1 Answers1

1

I think the relations' type is one, the relations' foreignType is many:

Menu:
  actAs:
    Timestampable:
      created:
        disabled: true
      updated:
        disabled: true
  columns:
    id: { type: integer, autoincrement: true, notnull: true, primary: true }
    name: { type: string(255), notnull: true }
    parent: { type: integer, notnull: false }
  relations:
    Parent:
      alias: parentItem
      class: Menu
      local: parent
      foreign: id
      type: one
      foreignAlias: childrens
      foreignType: many
      onDelete: CASCADE
sglessard
  • 3,097
  • 2
  • 27
  • 31