class Event < ActiveRecord::Base <br>
belongs_to :venue <br>
belongs_to :category<br>
end<br>
<br>
class Venue < ActiveRecord::Base<br>
belongs_to :city <br>
end<br>
<br>
class City < ActiveRecord::Base<br>
belongs_to :state<br>
end<br>
<br>
I want to retrieve all event records belonging to a state. Coming from hibernate background I tried something like this:<br>
<br>
def self.list_for_a_state(state_id)<br>
find_by_sql(["select e.* from venues v, events e where v.city.state_id= ? and e.venue_id = <a href="http://v.id">v.id</a>",state_id])<br>
end<br>
<br>
Error: Unknown table 'v.city' in where clause<br>
<br>
How do I handle this case?<br>
<br>
Thanks.<br>
<br>