This project is archived and is in readonly mode.
![Joshua J. Born Joshua J. Born](/images/avatar-large.gif)
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
-
Joshua J. Born May 13th, 2008 @ 10:45 PM
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.
-
-
josh July 17th, 2008 @ 01:38 AM
- State changed from new to stale
- Tag set to activerecord, bug
Closing this ticket as stale. If this is still an issue for you, feel free to reopen this ticket or create a new one with an updated description. Remember those unit tests too ;)
-
Pete P. April 1st, 2009 @ 04:33 AM
I've encountered this problem as well as detailed on this new 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>
People watching this ticket
Tags
Referenced by
-
2389 STI changes behavior depending on environment https://rails.lighthouseapp.com/...