Skip to content

#reset_column_information (from active_record/base) does not work properly with inheritance #22057

@common-nighthawk

Description

@common-nighthawk

reset_column_information only works on the Model that calls the method, and not on all models that inherit from it. This seems like bad behavior, because if you are going out of your way to call #reset_column_information--then you want all models that changed to be up to date.

I created a small app that displays the problem here: https://github.com/common-nighthawk/rails-reset_column_information-bug

In summary, say I have two models--

class Animal < ActiveRecord::Base
end

class Bird < Animal
end

Both have 2 columns: id and type.

Then I run this migration--

add_column :animals, :greeting, :string
Animal.reset_column_information
Animal.find_by(type: nil).update_attributes(greeting: 'im an animal')
Animal.find_by(type: 'Bird').update_attributes(greeting: 'im a bird')

The Animal will have greeting 'im an animal' and the Bird will have greeting 'nil'.

I can get around this by calling #reset_column_information on all Models explicitly. But this feel clunky, because all models that inherit from the parent have changing columns--so I don't see why the method call should not update all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions