This project is archived and is in readonly mode.
STI sub classes not loaded until parent is
Reported by Ian Ownbey | May 2nd, 2008 @ 01:23 AM
When using STI, a Uninitialised Constant error is thrown when calling subclasses (Doc in following example) before parent class is called (container in following example).
Ex:
class Container < ActiveRecord::Base
end
class Doc < Container
end
Doc
#=> uninitialized constant Doc
Container
#=> Okay
Doc
#=> Okay
Comments and changes to this ticket
-
Ian Ownbey May 2nd, 2008 @ 02:51 AM
ooooo all the STI are in the same file as the model. This could be creating the problem.
-
Frederick Cheung May 2nd, 2008 @ 09:58 AM
That will definitely be a problem. If they are both in container.rb, how can the dependencies mechanism know that if you hit const_missing for Doc you need to look in container.rb?
-
DHH May 3rd, 2008 @ 05:03 PM
- State changed from new to resolved
Auto-loading only works when each class is in its own file. If you want to keep all the files in one, you can always force the load with require_dependency 'container' some where.
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>