Monday, 15 August 2011

ruby on rails - Searching model based on relationships -



ruby on rails - Searching model based on relationships -

i have topic model belongs_to trip. trip has start_date , end_date. want find topics based on trips date. how set query in rails?

topic.joins(:trip).where('trip.start_date > ?', time.now)

this throws next error.

topic load (0.3ms) select "topics".* "topics" inner bring together "trips" on "trips"."id" = "topics"."trip_id" (trip.start_date < '2014-10-22 13:17:37.764743') order created_at desc sqlite3::sqlexception: no such column: trip.start_date: select "topics".* "topics" inner bring together "trips" on "trips"."id" = "topics"."trip_id" (trip.start_date < '2014-10-22 13:17:37.764743') order created_at desc activerecord::statementinvalid: sqlite3::sqlexception: no such column: trip.start_date: select "topics".* "topics" inner bring together "trips" on "trips"."id" = "topics"."trip_id" (trip.start_date < '2014-10-22 13:17:37.764743') order created_at desc

how structuring query wrong?

table names in rails convention plural (contrary model names) , it's case here, according log. should be:

topic.joins(:trip).where('trips.start_date > ?', time.now)

ruby-on-rails

No comments:

Post a Comment