I've 5 tables :
**areas**
id
otherfields
**realtors**
id
otherfields
**users**
id
otherfields
**areas_realtors**
area_id
realtor_id
**areas_users**
area_id
user_id
My relation in models are :
class Area < ActiveRecord::Base
has_and_belongs_to_many :users
has_and_belongs_to_many :realtors
end
class AreasRealtor < ActiveRecord::Base
belongs_to :realtor
belongs_to :area
end
class AreasUser < ActiveRecord::Base
belongs_to :user
belongs_to :area
end
class Realtor < ActiveRecord::Base
has_and_belongs_to_many :areas
end
class User < ActiveRecord::Base
has_and_belongs_to_many :areas
end
In my "realtor controller", i need to select all the users with common areas with the realtor.
I don't found the solution with Active Record or with "simple MySQL query"...
Thanks for advance,
F.