This project is archived and is in readonly mode.
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
-
CancelProfileIsBroken May 26th, 2009 @ 01:42 PM
- 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
-
Valentin Mihov May 26th, 2009 @ 01:46 PM
Should it be just a diff or I can branch the code in github and write the test there?
-
CancelProfileIsBroken May 26th, 2009 @ 01:57 PM
Just attach a diff with a failing test here. The contributing guide will walk you through constructing the diff if you need help.
-
Valentin Mihov May 26th, 2009 @ 02:25 PM
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?
-
CancelProfileIsBroken May 26th, 2009 @ 02:39 PM
- 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 :)
-
Valentin Mihov May 26th, 2009 @ 03:19 PM
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? -
CancelProfileIsBroken May 26th, 2009 @ 03:26 PM
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.
-
Valentin Mihov May 26th, 2009 @ 03:49 PM
Yes. It applies fluently.
I will look around the code later and try to figure out a fix for the problem.
-
Rohit Arondekar October 9th, 2010 @ 04:12 AM
- 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.
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>