# Associations and find

**URL:** <https://www.ruby-forum.com/t/associations-and-find/103640>\
**Category:** Rails\
**Created:** [May 8, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/associations-and-find/103640 "2007-05-08T19:31:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![najt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ab097/32.png) [@najt](https://www.ruby-forum.com/u/najt)\
**Post date:** [May 8, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/associations-and-find/103640/1 "2007-05-08T19:31:22Z")

</div>

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
