Rails where condition with nil value

前端 未结 5 913
我在风中等你
我在风中等你 2021-02-05 03:16

I found out that using where with symbol :my_id => nil and using old school one with ? is different. Could anyone explain me why?

MyTable.where(\"my_id = ? \", n         


        
5条回答
  •  长情又很酷
    2021-02-05 03:46

    For DB for NULL the syntax should be

    my_id IS NULL
    

    So you can give it as:

    MyTable.where("my_id is NULL ").first
    

提交回复
热议问题