has_many :through and has_one :through associations

Hello,

First I’m using Rails 3.1 from the 3-1-stable branch updated an hour ago.

I’m developing an application where I have 3 essential models User, Company and Job, Here’s the relevant part of the models:

class User < ActiveRecord::Base

has_many :companies_users, class_name: "CompaniesUsers"

has_many :companies, :through => :companies_users, :source => :company

end

class Company < ActiveRecord::Base

has_many :companies_users, class_name: “CompaniesUsers”

has_many :employees, :through => :companies_users, :source => :user

has_many :jobs, :dependent => :destroy

PGP.sig (243 Bytes)