【发布时间】: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