How to delete parent object when last associated child is deleted?
I have a Family model that
has_many Kids. I'm using
dependent: :destroy on the family so when it is destroyed the associated kids are destroyed too. All good.
Now I need to destroy the family when the last associated kid is deleted. This is to prevent stray families in the database that have no kids.
Should I do it in
students_controller#destroy method? Or is there a better way?