Help with find

I have the following

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

please guide me on how this can be done.

I have the following

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

Fred

For slighly more idiomatic Ruby, you could use the attribute name “active” rather than “is active”. The resulting query would then look something like:

Province.joins(:cities).where(:active => true).where(“cities.active = ?”, true)