# authorization build in model?

**URL:** <https://discuss.rubyonrails.org/t/authorization-build-in-model/891>\
**Category:** rubyonrails-talk\
**Created:** [August 31, 2006, 11:42pm UTC](https://discuss.rubyonrails.org/t/authorization-build-in-model/891 "2006-08-31T23:42:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Muermann](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@Max\_Muermann](https://discuss.rubyonrails.org/u/Max_Muermann)\
**Post date:** [August 31, 2006, 11:42pm UTC](https://discuss.rubyonrails.org/t/authorization-build-in-model/891/1 "2006-08-31T23:42:56Z")

</div>

Read up on ActiveRecord with\_scope - you might want to do something like this:

Patient.with\_scope( :find=\>{:conditions=\>[''groups.user\_id=?",User.current\_user], :include=\>[:groups]} ) do &nbsp;&nbsp;Patient.find(:all, :conditions=\>\<other conditions for patient go here\>, ...) end

This is a really nicely structured way of separating the authorisation concern from the actual query.

Note that you could also include the user table: :include=\>{:groups=\>:user} and then use users.user\_id in the condition.

Cheers, Max
