Jim Burgess wrote in post #973132:
> I have a flight model.
> I want to find all flights with a specific arrival airport, a specific
> departure airport and which depart on a certain date.
>
> My problem is that the departure date is a datetime column in the db and
> I wish to search this column by date (not datetime).
>
> @flights = Flight.find(:all, :conditions => ['arrival_airport_id = ? and
> departure_airport_id = ? and departure_datetime >= ? and
> departure_datetime < ?', @arrival_airport_id, @departure_airport_id,
> @date, @date+1])

Rails 2:
@flights = Flight.find(:conditions => { :arrival_airport_id => 
departure_airport_id, :departure_datetime => @date...(@date + 1.day) })

Rails 3:
@flights = Flight.where(:arrival_airport_id => departure_airport_id, 
:departure_datetime => @date...(@date + 1.day))

SELECT "flights".* FROM "flights" WHERE ("flights"."arrival_airport_id" 
= 1) AND ("flights"."departure_datetime" >= '2011-01-07 17:21:56.932566' 
AND "flights"."departure_datetime" < '2011-01-08 17:21:56.932568')

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to