我正在尝试删除不止一个id。我目前使用的是
是否有一种方法可以选择多个数据记录?
Person.find(1).destroy
。是否有一种方法可以选择多个数据记录?
Person.find(1).destroy
。Person.find_each do |person|
if # condition for deleting
person.destroy
end
end
另外,如果您知道所有的id ... 您可以使用where子句,然后销毁它们所有。
ids = [1,2,3,4,5]
people = Person.where(id: ids) # where can take an array of ids
people.each { |person| person.destroy }
Person.where(id: [1,2,3]).destroy_all
和delete_all
(有关更多信息,请参见https://dev59.com/IWw15IYBdhLWcg3wT59c) - MrYoshiji