class Province < ActiveRecord::Base
has_many :cities
attr_accessible :name, :is_active
end
class City < ActiveRecord::Base
belongs_to :province
attr_accessible :name, :province_id, :is_active
end
now I want to get all the provinces with is_active = true which have
cities with is_active = true
You should be able to do this using the joins option to find (or in
rails 3 by calling .joins(...)) to join the cities table to the
provinces one. You'll then be able to write conditions that refer to
both tables
For slighly more idiomatic Ruby, you could use the attribute name “active” rather than “is active”. The resulting query would then look something like: