This project is archived and is in readonly mode.
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
-
Gunnar Wolf June 16th, 2008 @ 07:32 PM
Please comment on the attached patch - This is a first step only, I have not created any test cases, nor really tested it.
-
Pratik July 2nd, 2008 @ 02:41 AM
- State changed from new to incomplete
- Tag set to activerecord, bug, enhancement, patch
-
josh October 5th, 2008 @ 03:15 PM
- State changed from incomplete to wontfix
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>