Error Using the New Active Directory Query Interface in Rails 3


I'm trying to use the new Active Record Query Interface for Rails 3.

My old style query is

my_notes = Note.find(:all, :conditions => { :user_id =>, :date => p[:date] }, :order => "date ASC, created_at ASC")

In the new style, I thought it would be:

my_notes = Note.find_all_by_user_id_and_date(, p[:date]).order('date ASC, created_at ASC')

but I'm getting this error:

NoMethodError in NotesController#play
undefined method `order' for #<Array:0x00000103d23c38>

What am I doing wrong? Thanks for reading.

The new query interface works slightly differently - find_all_by_user_id_and_date will return an array of results, whereas order returns an ActiveRecord::Relation object that can then be further scoped.

A working query would be

my_notes = Note.order('date ASC, created_at ASC').find_all_by_user_id_and_date(, p[:date])

but it would generally be better to use the AREL syntax for your query:

my_notes = Note.where(:user_id =>, :date => p[:date]).order('date ASC, created_at ASC').all