This project is archived and is in readonly mode.
Single table inheritance bug only in production environment
Reported by Joshua J. Born | May 13th, 2008 @ 10:32 PM
With ActiveRecord 2.0.2, define the following classes.
class A < ActiveRecord::Base
class B < A
class C < B
Implement all three with single table inheritance. Create several instances of B and of C and save them in the database.
Call B.find(:all) in a controller list action.
If a development environment is loaded, then B.find(:all) will always return just objects of class B. Set a breakpoint on B.find(:all) in a debugger to verify this.
If a production environment is loaded, then the first time B.find(:all) is run it will return just objects of class B. However, on subsequent calls to B.find(:all), ActiveRecord returns objects of class C as well. This was checked with a debugger breaking as soon as B.find(:all) was called.
Loading a production environment in the console and running B.find(:all) multiple times seems to work correctly. This bug only occurs when called from within a controller.
Comments and changes to this ticket
I'm not sure why this occurred only when Rails was loaded in its production environment and not the development environment, but this seems to be due to the documented foible of ActiveRecord getting subclasses in STI only if the subclass module has been loaded.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Tickets have moved to Github
The new ticket tracker is available at https://github.com/rails/rails/issues