I have 2 tables in database: cars and domains. One car can have many domains and one domain can have many cars.
In my project three models:
class Car < ActiveRecord::Base
has_many :cars_domains
has_many :domains, :through => :cars_domains
...
class Domain < ActiveRecord::Base
has_many :cars_domains
has_many :cars, :through => :cars_domains
...
class CarsDomain < ActiveRecord::Base
belongs_to :car
belongs_to :domain
end
I want to see cars which without domain:
@cars = Car.find(:all, :conditions => ['id not in(select car_id from cars_domains where domain_id = ?)', params[:domain_id]])
It's work, but I think it's very difficult. Maybe possible to do it more simple?