# Having trouble editing self-reference join model attribute

**URL:** <https://www.ruby-forum.com/t/having-trouble-editing-self-reference-join-model-attribute/91154>\
**Category:** Rails\
**Created:** [April 5, 2007, 6:10am UTC](https://www.ruby-forum.com/t/having-trouble-editing-self-reference-join-model-attribute/91154 "2007-04-05T06:10:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinkaku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@shinkaku](https://www.ruby-forum.com/u/shinkaku)\
**Post date:** [April 5, 2007, 6:10am UTC](https://www.ruby-forum.com/t/having-trouble-editing-self-reference-join-model-attribute/91154/1 "2007-04-05T06:10:59Z")

</div>

I’m a newbie in rails and working on my first project with it. I have a  
database that uses a self reference through a join model to add  
favorite players. In the join model I have an additional attribute for  
players to make notes of each favorite player.

My problem is I’m having difficulty editing the note attribute. All the  
favorite players are displayed all at once along with their notes. I do  
this by using fields\_for, but I can only capture the first note of the  
page when I post.

##view  
\< fields\_for “favorite\_user”, @favs[index] do |favorite\_note| %\>  
\<= favorite\_note.text\_area :note, “rows” =\> 5 %\>  
\< end %\>

##controler  
def favorites  
if request.get?  
@players = Player.find(params[:id]).favorites  
@favs = FavoriteUser.find\_all\_by\_player\_id(params[:id])  
elsif request.post?  
self\_player = Player.find(params[:id])  
p @params ##check to see if I got all the notes?  
end  
end

## model

class Player \< ActiveRecord::Base  
has\_many :favorite\_users  
has\_many :favorites, :through =\> :favorite\_users  
end

class FavoriteUser \< ActiveRecord::Base  
belongs\_to :player  
belongs\_to :favorite, :foreign\_key =\> “favorite\_id”, :class\_name =\>  
“Player”  
end

## database tables

CREATE TABLE `players` (  
`id` int(11) NOT NULL auto\_increment,  
`username` varchar(50) NOT NULL,  
PRIMARY KEY (`id`)  
);

CREATE TABLE `favorite_users` (  
`player_id` int(11) default NULL,  
`favorite_id` int(11) default NULL,  
`note` varchar(100) default NULL  
);
