# Has\_many with different foreign key

**URL:** <https://www.ruby-forum.com/t/has-many-with-different-foreign-key/159095>\
**Category:** Rails\
**Created:** [January 31, 2009, 12:52pm UTC](https://www.ruby-forum.com/t/has-many-with-different-foreign-key/159095 "2009-01-31T12:52:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sSshartles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@sSshartles](https://www.ruby-forum.com/u/sSshartles)\
**Post date:** [January 31, 2009, 12:52pm UTC](https://www.ruby-forum.com/t/has-many-with-different-foreign-key/159095/1 "2009-01-31T12:52:10Z")

</div>

Hello,

I am new to rails and am trying to get my associations straight. I  
have a User model and a Property model. I’d like to track who has  
updated a property record, so I added an integer field to the  
properties table called updated\_by. Then I made the following  
changes:

In the User model:  
has\_many :properties

In the Property model:  
belongs\_to :user, :class\_name =\> “User”, :foreign\_key =\>  
‘updated\_by’

Here’s what I see inside of the rails console:

> > prop = Property.first  
> > =\> #\<Property id: 1, name: “Main Street Center”, …, updated\_by: nil\>
> 
> > usr = User.first  
> > =\> #\<User id: 1, login: “sshartles”, name: “Sam Shartles”, … \>
> 
> > prop.user = usr  
> > =\> #\<User id: 1, login: “sshartles”, name: “Sam Shartles”, … \>
> 
> > prop.updated\_by  
> > =\> 1
> 
> > prop.updated\_by.name  
> > NoMethodError: undefined method `name’ for 1:Fixnum  
> > from (irb):5
> 
> >

I’m not sure what I’ve done, but I think it’s something simple. Any  
help would be massively appreciated.

Sam
