This is happens on Sqlite. I am probably missing something but I couldn't figure out what exactly.
Consol开发者_高级运维e Output
>> date = Task.first.date
=> Tue, 16 Aug 2011
>> Task.find(:all, :conditions => {:date => date})
=> []
>> Task.find(:all, :conditions => ['date = ?', date])
=> []
>> Task.find(:all, :conditions => ['date IS ?', date])
=> []
Schema
create_table "tasks", :force => true do |t|
t.date "date"
end
This is not a complete answer but hopefully will put your mind at ease that your syntax is correct
I knocked up a quick app to test this and all your methods of retrieval work. This was with an SQLite database also and there were no errors.
t = Task.create
=> #<Task id: 1, date: nil, created_at: "2011-08-23 14:32:27", updated_at: "2011-08-23 14:32:27">
t.date = "Tue, 16 Aug 2011"
=> "Tue, 16 Aug 2011"
t.save
date = Task.last.date
=> Tue, 16 Aug 2011
Task.find(:all, :conditions => {:date => date})
=> [#<Task id: 1, date: "2011-08-16">]
Task.find(:all, :conditions => ['date = ?', date])
=> [#<Task id: 1, date: "2011-08-16">]
Task.find(:all, :conditions => ['date IS ?', date])
=> [#<Task id: 1, date: "2011-08-16">]
My schema.rb:
create_table "tasks", :force => true do |t|
t.date "date"
end
Even I tried in my local db and everything seems to work fine.
The to_sql method will return the query generated by rails. That might help you in debugging the issue:
Task.where(:date => date).to_sql
精彩评论