has_many through relationship with conditions based on relationship table (Rails 2.3.5)

I have a relationship that is as follows.

belongs_to :employee
belongs_to :company
validates_presence_of :role

has_many :companies_employees
has_many :companies, :through => :companies_employees

has_many :companies_employees
has_many :managers, :through => :companies_employees, :source => :employee, conditions => {:role => "Manager"}
has_many :owners, :through => :companies_employees, :source => :employee, :conditions => {:role => "Owner"}

My problem is that when it checks the conditions, it tries to find the role column in the employees table, but the role column is in the companies_employees table. Is there a way to make it use things in this table for the conditions?


Try something like this:

has_many :managers, :through => :companies_employees, :source => :employee, conditions => ["employees.role = 'Manager"]
has_many :owners, :through => :companies_employees, :source => :employee, conditions => ["employees.role = 'Owner"]

Need Your Help

QueryStringBindable for a custom enum

java enums playframework query-string

I've defined an enum type Format that implements QueryStringBindable. I think I've implemented it correctly, but in my routes file, I can't specify my type as a route parameter, because the compile...