2

I have the following query in rails...

@registrations = Registration.where(Orientation.where(class_date: @start_date..@end_date))

The query itself does not throw an error, however if I try to inspect @registrations do anything with the variable I get the error...

Cannot visit ActiveRecord::Relation

Any ideas?

Mark Locklear
  • 5,044
  • 1
  • 51
  • 81

1 Answers1

4

Orientation.where(class_date: @start_date..@end_date)

does the range query you like

SELECT * FROM orientations WHERE class_date BETWEEN <start_date> AND <end_date>

UPDATE

Registration.where(created_at: @start_date..@end_date).
  joins(:orientation).
  where('orientations.created_at' => @start_date..@end_date)

will make the following SQL which I think is what you need

SELECT registrations.* FROM registrations INNER JOIN orientations ON orientations.id = registrations.orientation_id WHERE (registrations.created_at BETWEEN '2014-02-17 16:01:41' AND '2014-02-19 16:01:41') AND (orientations.created_at BETWEEN '2014-02-17 16:01:41' AND '2014-02-19 16:01:41')
xlembouras
  • 8,215
  • 4
  • 33
  • 42