我在MySQL InndoDB数据库中使用Doctrine's 2 Tree-Nestedset extension。
yml 表架构如下所示:
Ext\Entity\PageElement:
type: entity
table: page_element
repositoryClass: Gedmo\Tree\Entity\Repository\NestedTreeRepository
gedmo:
tree:
type: nested
id:
id:
type: integer
generator:
strategy: AUTO
fields:
element_object_data:
type: array
nullabe: true
element_object_type:
type: string
nullable: true
lft:
type: integer
gedmo:
- treeLeft
rgt:
type: integer
gedmo:
- treeRight
root:
type: integer
gedmo:
- treeRoot
lvl:
type: integer
gedmo:
- treeLevel
sort_order:
type: integer
nullable: true
created:
type: datetime
gedmo:
timestampable:
on: create
updated:
type: datetime
gedmo:
timestampable:
on: update
manyToOne:
parent:
targetEntity: Ext\Entity\PageElement
inversedBy: children
gedmo:
- treeParent
oneToMany:
children:
targetEntity: Ext\Entity\PageElement
mappedBy: parent
尝试删除包含子节点的任何节点我得到mysql错误:
PDOException:SQLSTATE [23000]:完整性约束违规:1451 无法删除或更新父行:外键约束失败 (
page_element
,CONSTRAINTpage_element_ibfk_1
FOREIGN KEY (parent_id
)参考page_element
(id
))
据我所知,这是因为InnoDB参考限制,但我不确定如何避免它?