如何销毁 table in ruby on rails 中等于和不等于条件的数据
how to destroy data from table in ruby on rails with eqaul to and not eqaul to condition
我想从 spree_stock_items
中删除数据,其中 variant _id
等于 @varians.id
而 stock_location
不等于 stock_loc.id
。我尝试了以下语法但没有working.What 是正确的语法吗?
Spree::StockItem.where(:variant_id => @variants.id, :stock_location_id !=> stock_loc.id).destroy_all
你可以试试
Spree::StockItem.where("variant_id = ? and stock_location_id != ?", @variants.id, stock_loc.id).destroy_all
或
Spree::StockItem.where(:variant_id => @variants.id).where.not(:stock_location_id => stock_loc.id).destroy_all
我想从 spree_stock_items
中删除数据,其中 variant _id
等于 @varians.id
而 stock_location
不等于 stock_loc.id
。我尝试了以下语法但没有working.What 是正确的语法吗?
Spree::StockItem.where(:variant_id => @variants.id, :stock_location_id !=> stock_loc.id).destroy_all
你可以试试
Spree::StockItem.where("variant_id = ? and stock_location_id != ?", @variants.id, stock_loc.id).destroy_all
或
Spree::StockItem.where(:variant_id => @variants.id).where.not(:stock_location_id => stock_loc.id).destroy_all