# Saturday, September 26, 2015¶

## Deleting polymorphic objects¶

It took me some hours of sleep to understand #503 (Cannot delete some instances of model ‘Person’ because they are referenced through a protected foreign key: ‘Client.person_ptr’).

The explanation is: in case of MTI, every MTI child model has a pointer to its MTI parent. This pointer is a foreign key with on_delete set to CASCADE. Lino now automatically protects all foreign keys that need it. But the logics for deciding whether protection is needed had a bug which caused Lino to also protect these pointers to the MTI parent. The whole thing is now encapsulated in the kernel’s protect_foreignkeys method. Note that only subclasses of Polymorphic have this automatism.

I wrote a test case lino_welfare.projects.std.tests.test_ddh.