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.

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

#2720

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'

Reported by Valentin Mihov · May 26th, 2009 @ 01:36 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to incomplete

    As a practical matter, if you want to get some attention to this, the first step is to submit at least a failing test patch to the version of Rails you're using. See http://guides.rubyonrails.org/contributing_to_rails.html

    May 26th, 2009 @ 01:42 PM

  2. Valentin Mihov
    Valentin Mihov

    Should it be just a diff or I can branch the code in github and write the test there?

    May 26th, 2009 @ 01:46 PM

  3. CancelProfileIsBroken
    CancelProfileIsBroken

    Just attach a diff with a failing test here. The contributing guide will walk you through constructing the diff if you need help.

    May 26th, 2009 @ 01:57 PM

  4. Valentin Mihov
    Valentin Mihov

    A quite simple unit test for the described issue. It shows the issue in a much more simple way than I described ;-) The unit test is written on the origin/2-2-stable branch.

    Should I try that unit test in the rails-edge also?

    May 26th, 2009 @ 02:25 PM

  5. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from incomplete to new

    Thanks!

    Ideally, we'd want to know whether the issue persists on 2-3-stable and on master.

    Bonus points if you can come up with a patch to fix it :)

    May 26th, 2009 @ 02:39 PM

  6. Valentin Mihov
    Valentin Mihov

    Thanks for the help!

    The issue persists on the master branch and on 2-3-stable. Should I submit separate patches with the test for these?
    Any naming conventions if I do that?

    May 26th, 2009 @ 03:19 PM

  7. CancelProfileIsBroken
    CancelProfileIsBroken

    I suspect that patch will apply cleanly across all 3 branches - don't think there's been much change in that area of code lately. If not, you could just put the version in the patch title, there's no formal naming convention.

    May 26th, 2009 @ 03:26 PM

  8. Valentin Mihov
    Valentin Mihov

    Yes. It applies fluently.

    I will look around the code later and try to figure out a fix for the problem.

    May 26th, 2009 @ 03:49 PM

  9. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  10. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:12 AM