Я использую symfony 1.4.5, Doctrine 1.2 и Mysql 5.
В моей schema.yml у меня есть несколько отношений Many-to-Many, которые отлично работают. Но мне нужен стол для соединения, чтобы иметь 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 игнорируется.
Кто-нибудь знает, как заставить это работать?
На самом деле мой первоначальный ответ верен. Вот как я делаю это в приложении, которое я создаю.
Таким образом, UserSearch имеет таблицу соединений m-m под названием SearchTag. Но я хочу каскадировать мое удаление 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]
delete: [cascade]
к обеим сторонам существующего отношения вместо создания нового отношения (которое я тоже не понимаю)?