This project is archived and is in readonly mode.

#431 ✓wontfix
Gunnar Wolf

Table-modifying methods lead to inconsistent objects

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

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.

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>

People watching this ticket