2014-02-20 87 views
0

嘿人們試圖做一個簡單的查詢,我發現所有記錄的特定屬性爲零。在這種情況下...Rails where子句不等於零

irb(main):009:0> Registration.where(:registration_cancellation_token != nil) 
    Registration Load (0.2ms) SELECT `registrations`.* FROM `registrations` WHERE (1) 
=> [#<Registration id: 1, orientation_id: 13, first_name: "mark", last_name: "Busta", email: "[email protected]", student_id: "3232333", phone: "3884448333", registration_cancellation_token: nil, registration_cancelled_at: nil, checked_in: false, created_at: "2014-02-20 13:46:31", updated_at: "2014-02-20 13:46:31">] 

...但查詢返回所有註冊。感謝所有幫助...

+0

可惜你不能做一個漂亮的方式(至少不能以'軌3.2'以下) – xlembouras

回答

4

Registration.where("registration_cancellation_token IS NOT NULL")

+0

熱潮!你釘住了它!謝謝! – Lumbee

+0

歡迎:)請接受我的回答請 – Zakwan

+0

耐心小蚱蜢。 ;) – Lumbee

4
Registration.where.not(registration_cancellation_token: nil) 

這適用於軌道4

+0

在Rails 3中沒有工作,但thanx發佈。 – Lumbee