What's the rails way to include a field in a join model when listing an association? -


so if have following relationship

class item < activerecord::base    has_many :item_user_relationships    has_many :users, :through => :item_user_relationships end  class user < activerecord::base    has_many :item_user_relationships    has_many :items, :through => :item_user_relationships end  class itemuserrelationship < activerecord::base    belongs_to :item    belongs_to :user     attr_accessible :role end 

what's rails way include role attribute when listing users of item?

@users = @item.users # want include role part of user  

thanks!

update: i'm still having trouble this. goal array of user models have role included in attributes.

i'm note sure if understand correctly, maybe want?

@users = @item.users @users.each |user|   puts user.item_user_relationships.first.role end 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -