This project is archived and is in readonly mode.

#2962 ✓stale
johan.rejeep (at gmail)

Changed attribute value when fetched through association

Reported by johan.rejeep (at gmail) | July 28th, 2009 @ 12:06 PM


I found a weird behavior working on a Rails app of mine. I'm not sure if it's a bug. I attached a Rails app with the problem. The problem is reproduced by:

$ ./script/console
>> User.find(1).events
=> [#<Event id: 1, user_id: 1, eventable_id: 1, eventable_type: "Product", created_at: "2009-07-28 12:36:35", updated_at: "2009-07-28 12:40:44">, #<Event id: 2, user_id: 1, eventable_id: 1, eventable_type: "Product", created_at: "2009-07-28 12:36:59", updated_at: "2009-07-28 12:40:54">]
>> Event.find(1).user_id
=> 1
>> Event.find(2).user_id
=> 2

As you can see does not the user_id match.

I fixed the problem by renaming the user_id column in Event to publisher_id and also change the association to this in the event model:

belongs_to :publisher, :class_name => 'User'

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>