Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Changed attribute value when fetched through association

#2962

Hi!

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'

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 6th, 2010 @ 06:47 AM

  2. bingbing