Feature(s) impacted
Record Deletion (default route behavior)
Observed behavior
When deleting records using the default route behavior (RecordRemover), if the deleting record is part of a scoped, polymorphic association, the through table record is not deleted.
FA does handle record creation correctly for these scoped, polymorphic-associated models, e.g. creatring a new record automatically creates the correct through table record.
Expected behavior
Through table record should be deleted.
Context
OwnableLink Table:
owned_table: varchar(255)
owned_foreign_key: char(36)
owner_table: varchar(255)
owner_foreign_key: char(36)
(Simplified, example) Model relationships:
Book.belongsToMany(Author, {
through: {
model: db.OwnableLink,
unique: false,
scope: {
owned_table: Book.name,
owner_table: Author.name
}
},
foreignKey: 'owned_foreign_key',
constraints: false
})
Book.addScope(Author.name, (ownerID) => {
return {
include: [{
model: Author,
attributes: [],
where: {
id: ownerID
}
}]
}
})
Book.hasMany(db.OwnableLink, {
foreignKey: 'owned_foreign_key',
constraints: false,
onDelete: 'cascade',
hooks: true
})
Author.belongsToMany(Book, {
foreignKey: 'owner_foreign_key',
constraints: false,
through: {
model: db.OwnableLink,
unique: false,
scope: {
owner_table: Author.name,
owned_table: Book.name
}
},
onDelete: 'cascade',
hooks: true
})
- Agent : forest-express-sequelize v9.2.9
- Database type: SQL