is there way following?:
>items=item.where('location_id=?',8) >items.count # 12; delete of them >items.destroy i know item.destroy_all('location_id=?',8) i'd rather count check work before destructive operation.
thx
you can via activerecord::relation#destroy_all method:
items.destroy_all or
item.destroy_all(location_id: 8) each record destroyed 1 one. if want delete quickly, without additional checking, use delete_all instead:
items.delete_all # or item.delete_all(location_id: 8)
Comments
Post a Comment