# Chaining objects in activeRecord, and accessing attributes from parent

**URL:** <https://www.ruby-forum.com/t/chaining-objects-in-activerecord-and-accessing-attributes-from-parent/128939>\
**Category:** Rails\
**Created:** [February 12, 2008, 9:03pm UTC](https://www.ruby-forum.com/t/chaining-objects-in-activerecord-and-accessing-attributes-from-parent/128939 "2008-02-12T21:03:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![terry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terry](https://www.ruby-forum.com/u/terry)\
**Post date:** [February 12, 2008, 9:03pm UTC](https://www.ruby-forum.com/t/chaining-objects-in-activerecord-and-accessing-attributes-from-parent/128939/1 "2008-02-12T21:03:37Z")

</div>

Say I have Users table, and the user has many :items, if I define a  
method in the Item model say, def self.green so I can return all green  
items that belong to a user, I might use with\_scope. fine, so I use  
like this: @user.items.green.

But what if there is a preferences table so the user wants the items  
to be displayed in ascending order only, how would I access that from  
the def self.green method in the items model?

So, I called @users.items.green, and I want to access user.preferences  
from the items model. Is this possible?
