Forum: Ruby on Rails has_many with different foreign key

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
s. shartles (Guest)
on 2009-01-31 13:52
(Received via mailing list)

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

In the User model:
  has_many :properties

In the Property model:
  belongs_to :user, :class_name => "User", :foreign_key =>

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
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.

This topic is locked and can not be replied to.