Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
No delete for you today


Don’t use delete_all

Let’s say you have a has_many relationship – project has_many stories. You don’t have dependent: destroy on the association.

If you call project.stories.delete_all, it does not delete the stories. Instead, it inserts NULL into the stories’ project_id field.

As a bonus, if the project_id field in the stories table has a not null constraint, then all of the project_ids become 0 – potentially attaching themselves to a completely different project.

delete_all works properly if the association has a dependent: destroy clause, and destroy_all works properly in either case.

Share This