The goal: when a User is deleted, all entries for a user in UserCategory should be deleted as well.
The schema:
User:
actAs: { Timestampable: ~ }
columns:
first_name: { type: string(255) }
name: { type: string(255) }
company: { type: string(255) }
email: { type: string(255) }
phone: { type: string(255) }
language_id: { type: integer, notnull: true }
token: { type: string(255) }
activated: { type: boolean, default: false }
relations:
Categories:
class: Category
local: user_id
foreign: category_id
refClass: UserCategory
type: many
UserCategory:
actAs: { Timestampable: ~ }
columns:
user_id: { type: integer, notnull: true }
category_id: { type: integer, notnull: true }
Category:
actAs: { Timestampable: ~ }
columns:
language_id: { type: integer, notnull: true }
name: { type: string(255), notnull: true, unique: false }
revision: { type: integer, notnull: false }
icon: { type: string(255) }
relations:
User:
class: User
local: category_id
foreign: user_id
refClass: UserCategory
type: many
What happens:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
testtable.user_category, CONSTRAINTuser_category_user_id_user_idFOREIGN KEY (user_id) REFERENCESuser(id))
Like greg0ire said, defining a cascade for UserCategory did the job. It missed the relations block entirely: