问题描述
我正在使用symfony 1.4.5,Doctrine 1.2和Mysql5。
I'm using symfony 1.4.5, Doctrine 1.2 and Mysql 5.
在我的schema.yml中,我有一些多对多关系可以正常工作大。但是我需要在联接表上具有onDelete:CASCADE。
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.
现在,对于学说,需要在外键存在的那一侧添加onDelete:CASCADE,但是由于refclass确实存在架构中没有任何关系。yml我无法。
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.
示例架构:
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被忽略了。
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.
因此UserSearch有一个m-m连接表,称为SearchTag。但是我想将对UserSearch的删除级联到SearchTag表。
So UserSearch has a m-m join table called SearchTag. But I want to cascade my deletes of UserSearch to the SearchTag table.
因此,我明确定义了与SearchTag的关系,并将级联放置在该房地产上。
So I explicitly define the relationship to SearchTag and put the cascade on that realtionship.
我不喜欢使用ondelete,因为它意味着您可以在phpmyadmin等中破坏内容,因此使用 cascade:[delete]表示所有删除操作均由
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]
这篇关于symfony固定装置:set ondelete:refclass表上的CASCADE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!