如何根据两个条件从Ruby Sequel表中删除行

时间:2017-03-01 16:51:21

标签: mysql ruby-on-rails ruby database

我有一个表(设备),我正在使用Ruby访问。如果满足以下两个条件,我想删除一行:

{:user_id => params[:user_id]}

{:reg_token => params[:reg_token]}

但是,我不确定我是否知道如何正确使用AND。我正在尝试遵循本指南:

http://sequel.jeremyevans.net/rdoc/files/doc/dataset_filtering_rdoc.html

if Device.where{Sequel.&({:user_id => params[:user_id]}, {:reg_token => params[:reg_token]})}.count > 0
    # device = Device.where((:user_id => params[:user_id]) & (:reg_token => params[:reg_token])).delete
    device = Device.where{Sequel.&({:user_id => params[:user_id]}, {:reg_token => params[:reg_token]})}.delete
end

1 个答案:

答案 0 :(得分:0)

我只想链​​接where子句:

devices = Device.where(user_id: params[:user_id]).where(reg_token: params[:reg_token])
devices.delete_all