symfony fixtures:在refclass表上设置ondelete:CASCADE

时间:2010-06-23 10:08:43

标签: mysql symfony1 doctrine fixtures

我正在使用symfony 1.4.5,Doctrine 1.2和Mysql 5.

在我的schema.yml中,我有一些很多对多的关系。但我需要连接表有onDelete:CASCADE。

现在对于教义,需要在外键存在的一侧添加onDelete:CASCADE,但由于refclass在schema.yml中没有任何关系,我不能。

示例模式:

Organisatie:
  connection: doctrine
  tableName: organisatie
   columns:
    org_id:
     type: integer(4)
     fixed: false
     unsigned: false
     primary: true
     autoincrement: true
   naam:
     type: string(30)
     fixed: false
     unsigned: false
     primary: false
     notnull: true
     autoincrement: false
   relations:
     Sc:
      class: Sc
      refClass: ScRegel
      local: org_id
      foreign: sc_id

Sc:
  connection: doctrine
  tableName: sc
  columns:
    sc_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
      notnull: true
    sc_nummer:
      type: string(15)
      fixed: false
      unsigned: false
      primary: false
      autoincrement: false
      notnull: true
    type:
      type: string(20)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    Organisatie:
      class: Organisatie
      refClass: ScRegel
      local: sc_id
      foreign: org_id

 ScRegel:
  connection: doctrine
  tableName: sc_regel
  columns:
    sc_id:
      type: integer(4)
      primary: true
      autoincrement: true
      notnull: true
    sc_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      autoincrement: false
      notnull: true
    org_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false

现在我尝试在两侧添加onDelete:CASCADE(Sc和Organisatie),但在这两种情况下它们都被忽略,关系已经完成,但onDelete被忽略。

有人知道如何让这个工作吗?

1 个答案:

答案 0 :(得分:2)

其实我原来的答案是正确的。以下是我在正在构建的应用程序中执行此操作的方法。

因此,UserSearch有一个名为SearchTag的m-m连接表。但我想将删除的UserSearch级联到SearchTag表。

因此,我明确定义了与SearchTag的关系,并将级联放在该实现上。

我不喜欢使用ondelete,因为这意味着你可以在phpmyadmin等中破解,所以使用“cascade:[delete]”意味着所有删除都由应用程序处理。

UserSearch:
  actAs: [Timestampable]
  columns:
    user_id:
      type: integer(4)
    update_minutes: integer(4)
    last_ran: integer
    next_run: integer
    running: boolean
  relations:
    Tags:
      class: Tag
      local: search_id
      foreign: tag_id
      refClass: SearchTag
    SearchTags:
      local: id
      foreign: search_id
      class: SearchTag
      type: many
      foreignType: one
      cascade: [delete]

SearchTag:
  columns:
    search_id: 
      type: integer
      primary: true
    tag_id: 
      type: integer
      primary: true

Tag:
  columns:
    name: {type: string(255), notnull: true}
  relations:
    Searches:
      class: UserSearch
      local: tag_id
      foreign: search_id
      refClass: SearchTag
    SearchTags:
      local: id
      foreign: tag_id
      class: SearchTag
      type: many
      foreignType: one
      cascade: [delete]