Single association through multiple sources

at first i thought this might be an easy solution but then i realized
that there is a hmt association with users/jobs/projects and that
makes things more difficult.

I will however suggest a change and see if this works for you.
assuming a job is something like "tester", "developer", etc., why not
make "lead" a job as well and remove the lead_id from the project

that would leave you with:

class Project < AR::Base
  has_many :jobs

class Job < AR::Base
  belongs_to :project
  belongs_to :user

class User < AR::Base
  has_many :jobs
  has_many :projects, :through => :jobs do
    def by_jobname(jobname)
      find(:all, :conditions => [" = ?", jobname])

    def lead
      find(:all, :conditions => " = 'lead'")

then you can use the above association extensions like so:

u = User.find(...)

u.projects # => all projects in which the user has a job
u.projects.by_jobname('developer') # => all projects where user has a
developer job
u.projects.lead # => all projects where user has a lead job

you could even do the same with projects to find users based on job.


section on association extensions for more info.

hope this helps