mysql - symfony 装置 : set ondelete: CASCADE on refclass table

标签 mysql symfony1 doctrine fixtures

我正在使用 symfony 1.4.5、Doctrine 1.2 和 Mysql 5。

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

现在,为了 Doctrine ,需要在外键存在的一侧添加 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

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

有人知道如何让它工作吗?

最佳答案

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

因此 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]

关于mysql - symfony 装置 : set ondelete: CASCADE on refclass table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3100674/

相关文章:

forms - symfony 是否有一个内置的方法来将受污染的值与原始值进行比较?

php - 将数据插入多对多表 Symfony

php - 即时创建数据库备份

PHP Union - 仅当表名 = table1 时显示数据

mysql - 使用 case 语句优化查询

java - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException : Communications link failure

doctrine - PHP Doctrine 1.2 SET 语句中的条件 IF 语句

使用命名空间时找不到php Doctrine 类

php - 执行多个查询时的 Doctrine (DBAL) 错误处理

MySQL BETWEEN 与大于和小于