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.

Table-modifying methods lead to inconsistent objects

#431

When calling the column-related methods which modify a table's structure from ActiveRecord::ConnectionAdapters::SchemaStatements (i.e. add_column, remove_column, change_column, rename_column) not from a migration but from the application itself (i.e. when your application allows for table plasticity), the existing models remain with a stale definition - Take as an example the following console interaction:

>> Person

Person(id: integer, name: string)

>> Person.connection.add_column :people, :thing_id, :integer

=> []

>> Person

=> Person(id: integer, name: string)

To be able to use the new column, I have to do:

>> Person.reset_column_information

=> nil

>> Person

=> Person(id: integer, name: string, thing_id: integer)

So, what am I proposing? To modify the four mentioned methods so that, if there is a matching class defined in the current environment (i.e. no point in doing this when doing migrations, only if the classes have been brought to life), the model should be sent the reset_column_information.

The patch is trivial, I'm currently just checking it - but of course, I have not yet come up with a test case :) And I'd like some input before doing so.

In any case, expect my patch to appear here shortly.

Reported by Gunnar Wolf · June 16th, 2008 @ 07:17 PM

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

Activity

  1. Gunnar Wolf
    Gunnar Wolf

    Please comment on the attached patch - This is a first step only, I have not created any test cases, nor really tested it.

    June 16th, 2008 @ 07:32 PM

  2. Pratik
    Pratik
    • State changed from new to incomplete
    • Tag set to activerecord, bug, enhancement, patch

    July 2nd, 2008 @ 02:41 AM

  3. josh
    josh
    • State changed from incomplete to wontfix

    October 5th, 2008 @ 03:15 PM