I have three models:
class Address < ActiveRecord::Base
has_many :jobs
end
class Category < ActiveRecord::Base
has_many :jobs, :dependent => :destroy
end
class Job < ActiveRecord::Base
belongs_to :category
belongs_to :address
end
I'm trying to get all categories that the jobs has address_id != NULL I'm almost there doing:
categories = Category.find(:all,:joins=>:jobs,:conditions=>'jobs.address_id is not null')
the problem is that i have a lot of repeated categories. I can solve it doing a:
categories.uniq!
but is not exactly the best solution.. Any idea?