# Retrieving object from a user

**URL:** <https://www.ruby-forum.com/t/retrieving-object-from-a-user/176574>\
**Category:** Rails\
**Created:** [October 2, 2009, 12:27pm UTC](https://www.ruby-forum.com/t/retrieving-object-from-a-user/176574 "2009-10-02T12:27:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [October 2, 2009, 12:27pm UTC](https://www.ruby-forum.com/t/retrieving-object-from-a-user/176574/1 "2009-10-02T12:27:22Z")

</div>

Hi,

I would like which is the best way to implement this:  
I have an application with invoices, lines, accouts, etc… lots of  
models. Each element of a model belongs to a different user so when a  
user is logged he will see only his elements. I can implement this  
adding in all the find methods the condition :user\_id =\>  
params[:user\_id].

But, is there any other way that automatically adds this condition to  
all the queries if a user is logged in?

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [October 2, 2009, 1:01pm UTC](https://www.ruby-forum.com/t/retrieving-object-from-a-user/176574/2 "2009-10-02T13:01:43Z")

</div>

On Fri, Oct 2, 2009 at 12:27 PM, Juan K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## But, is there any other way that automatically adds this condition to all the queries if a user is logged in?

Have you defined relationships between those models?

–  
Leonardo M…  
There’s no place like ~
