Use transaction

to prevent inconsistent database on failure
Add support for polymorphic associations and STI