【问题标题】:I can't execute data-load (Symfony 1.4 Doctrine)我无法执行数据加载(Symfony 1.4 Doctrine)
【发布时间】:2012-11-22 13:01:56
【问题描述】:

我的 symfony 项目有问题。
我有一个带有 InnoDB 表的 MySQL 数据库。
我尝试创建简单的树形菜单:

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

在后端创建元素后,我执行data:dump 并获取此代码

夹具:

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

如果我尝试运行,我已经失去了项目之间的关系

我不明白出了什么问题。

编辑:

之前:

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

之后

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

【问题讨论】:

  • 你说的失去关系是什么意思?
  • @j0k 之前:| id | name | parent | | 1 | Parent | NULL | | 2 | Children | 1 | 之后| id | name | parent | | 1 | Parent | NULL | | 2 | Children | 0 |
  • @j0k 抱歉。我在 parent-col 中丢失了一个值。它变成了一个 0
  • 对我来说,一切似乎都很好,因为您使用parentItem 和父级密钥引用关系。奇怪..
  • @j0k 我尝试使用父级。没有变化。 (

标签: symfony1 doctrine symfony-1.4 fixtures data-dump


【解决方案1】:

我认为关系的类型是一,关系的foreignType是多的:

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

【讨论】:

    猜你喜欢
    • 2012-06-29
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    相关资源
    最近更新 更多