mysql - Rails query turns up empty, but same query retrieves records if serched in sql console -
ok, been 3 freaking days issue , im sure simple, cant seem figure out.
i've run issue after creating scope homecoming users birthday between 2 days along other conditions. info supposed presented user dashboard.
here bothers me, if refresh page, there 0 records found. if run scope in rails console (development environment) returns 0 records. however, if re-create query console (active logger on) , set straight sql client, returns right records. scope chained few other scopes well, if remove scope query chain, query works, doesn't filter date of birth ranges similar scope do.
yes sql client on same database.
the scope:
where( "(date_of_birth <= ?) or date_add(date_of_birth, interval ? year) between ? , ?", min_age.years.ago.to_date, min_age, beginning_of_month, end_of_month )
the query:
select drivers
.* drivers
( (date_of_birth <= '1990-02-05') or date_add(date_of_birth, interval 23 year) between '2013-04-01' , '2013-04-30') , (drivers.id not in (select driver_id follow_ups team_id = 2)) , (average_miles_per_day >= 0.35) , (travel_time < 2000) , (travel_time + (average_miles_per_day * 84) >= 2000)
anytime rails tries execute query doesn't work. when executing query in sql client, works charm.
maybe... there problem string date conversion. seek convert in model using str_to_date() function. please each date... allow me know it helps.
mysql sql ruby-on-rails ruby-on-rails-3 sequel
No comments:
Post a Comment