Associations and find

Hi. I have the following models

class User < ActiveRecord::Base
has_and_belongs_to_many :projects
end

class Project < ActiveRecord::Base
has_many :castings, :dependent => :destroy
has_many :candidates, :through => :castings
has_and_belongs_to_many :users
end

class Candidate < ActiveRecord::Base
has_many :castings, :dependent => :destroy
has_many :projects, :through => :castings, :uniq => true
end

class Casting < ActiveRecord::Base
belongs_to :project
belongs_to :candidate
end

What I need is when I issue a Candidate.find that it will only return
candidates for which the user has access to (via the projects_users
habtm).

I also need a way to check if the user has access to a specific
candidate.

Thank you

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs