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.

update_attribute from STI model does not work

#1414

When creating a STI solution, I noticed that an update_attribute call in the parent model does not work when called on the child models.

See the following gist for details on how to reproduce the problem:

http://gist.github.com/25721

At this moment, I'm completely in the dark about what's causing this problem.

Reported by Ariejan de Vroom · November 19th, 2008 @ 10:42 AM

State: stale
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Ariejan de Vroom
    Ariejan de Vroom
    • Tag changed from bug, sti, update_attribute to 2.2, bug, rails-2.2, sti, update_attribute

    More info:

    I'm using the latest Rails 2.2 gem with a MySQL database.

    November 19th, 2008 @ 10:52 AM

  2. Frederick Cheung
    Frederick Cheung

    Just for the record, this is nothing to do with STI.

    This happens if - You load a model - You change the association (build, create, or =) - You then change the foreign key

    As you may have already noticed, if foo belongs_to bar changing :bar_id will not cause the value of foo.bar to change if the association is already loaded and this is slightly connected. During the save activerecord thinks that the current value of the association is foo.bar and so overwrites the change you made to the foreign key

    December 16th, 2008 @ 01:02 PM

  3. Pratik
    Pratik
    • State changed from new to stale

    March 8th, 2009 @ 05:20 PM