This project is archived and is in readonly mode.

#2720 ✓stale
Valentin Mihov

Model updates not working correctly when used in a migration and a table with inheritance

Reported by Valentin Mihov | May 26th, 2009 @ 01:36 PM | in 3.x

When you have a model with single table inheritance and you try to make a migration, which is modifying the model's table and then updating it, the updates are not working correctly even if you use reset_column_information or put the updates in a separate migration.

Environment:

Rails 2.2.2

MySql - Ver 14.14 Distrib 5.1.30, for apple-darwin9.5.0 (i386) using readline 5.1

Steps to reproduce:
1. Unzip the attached rails project. It is an empty rails project with one model (Company) and 2 migrations. There is also a Firm model extending the Company

2. Run rake db:drop db:create db:migrate

3. Run ./script/runner "p Company.all". Notice that location of each company except 'Microsoft' is nil

4. Have a look at db/migrate/20090526120800_add_location_to_companies.rb, it should be updating all the locations to "US"<br/
5. Have a look at the development.log<br/

SQL (0.6ms) BEGIN

Company Update (0.4ms) UPDATE companies SET updated_at = '2009-05-26 12:27:19', location = 'US' WHERE id = 1

SQL (0.6ms) COMMIT

SQL (0.1ms) BEGIN

Company::Firm Update (0.3ms) UPDATE companies SET updated_at = '2009-05-26 12:27:19' WHERE id = 2

SQL (0.6ms) COMMIT

SQL (0.1ms) BEGIN

Company::Firm Update (0.2ms) UPDATE companies SET updated_at = '2009-05-26 12:27:19' WHERE id = 3

SQL (0.6ms) COMMIT

It is updating the first company, but is not updating the rest (only setting their :updated_at attribute).

Expected:

All the companies in the database to be updated with a location set to 'US'

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages