[Rails] Relationship navigation issue

Neeraj Kumar
Tue, 31 Jan 2006 18:21:11 -0000

class Event < ActiveRecord::Base
  belongs_to  :venue
  belongs_to  :category
end

class Venue < ActiveRecord::Base
  belongs_to  :city
end

class City < ActiveRecord::Base
  belongs_to  :state
end

I want to retrieve all event records belonging to a state. Coming from
hibernate background I tried something like this:

 def self.list_for_a_state(state_id)
    find_by_sql(["select e.* from venues v, events e where
v.city.state_id=? and
e.venue_id = v.id",state_id])
 end

Error: Unknown table ''v.city'' in where clause

How do I handle this case?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...