0

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 を追加しようとしました: 両側 (Sc と Organisatie) に CASCADE を追加しようとしましたが、どちらの場合も無視され、関係が作成されますが、onDelete は無視されます。

これを機能させる方法を知っている人はいますか?

4

1 に答える 1

2

実際、私の最初の答えは正しいです。これが、私が構築しているアプリケーションで行う方法です。

したがって、UserSearch には SearchTag という名前の mm 結合テーブルがあります。しかし、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]
于 2010-06-23T14:39:47.903 に答える