What is the most efficient way to delete an existing object from a Rails class? I have an array of objects
person_array = [Person1, Person2, Person3]
My goal is to delete all of the people in that array from a table in which they are members.
So I have a People class which they currently belong to.
I was thinking something like People.delete(person_array) which seems to be executing the proper SQL statements. How do I get those delete statements to actually change my People table though?
Since you already have the objects, you can just call
destroy_allwith them:Unlike
delete_all, this will invoke the model’s callbacks, which may take longer, but preserves integrity.