Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Model.where() returning a blank array (when I'm sure there are matches)?

What am I doing incorrectly that is giving me a blank array from this command?

Item.where(:load_date => Date.today + 2)

Here is my Rails Console:

.9.3-p194 :024 > Item.first.load_date
Item Load (0.3ms)  SELECT "items".* FROM "items" LIMIT 1
=> Fri, 24 May 2013 
1.9.3-p194 :025 > Item.where(:load_date => Date.today + 2)
Item Load (0.5ms)  SELECT "items".* FROM "items" WHERE "items"."load_date" = '2013-05-24'
=> []
1.9.3-p194 :026 > Item.first.load_date == Date.today + 2
Item Load (0.3ms)  SELECT "items".* FROM "items" LIMIT 1
=> true 

Item Model:

... 
#  load_date       :date
...

class Item < ActiveRecord::Base
attr_accessible :bt_num, :dept, :formula, :item_code, :load_date, :prod_comments, :qc_comments, :qc_tech, :qty_in_kg, :qty_in_liters, :rm_ok_by, :series, :status, :time_to_produce, :vat
...
like image 725
collenjones Avatar asked Nov 13 '22 05:11

collenjones


1 Answers

Try these

Item.where(:load_date => (Date.today + 2).strftime)
  or 
Item.where("Date(load_date) =?", (Date.today + 2).strftime)
like image 101
Harish Malik Avatar answered Nov 27 '22 06:11

Harish Malik