I'm using symfony 1.4.5, Doctrine 1.2 and Mysql 5.
In my schema.yml I have a few Many-to-Many relations which work great. But I need the joining table to have onDelete: CASCADE.
Now for doctrine it is needed to add onDelete: CASCADE on the side where the foreignkey exists but since the refclass does not have any relations in the schema.yml I can't.
example schema:
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
pri开发者_C百科mary: 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
Now i tried to add onDelete: CASCADE on both sides (Sc and Organisatie), but in both cases they are ignored, the relation is made, but the onDelete is ignored.
Does anybody know how to get this working?
Actually my original answer is in correct. Here is how I do it in an application I am building.
So UserSearch has a m-m join table called SearchTag. But I want to cascade my deletes of UserSearch to the SearchTag table.
So I explicitly define the relationship to SearchTag and put the cascade on that realtionship.
I don't like using ondelete as it means you can break things in phpmyadmin etc, so using "cascade: [delete]" means all the deletes are handled by the application.
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]
精彩评论