This project is archived and is in readonly mode.
STI changes behavior depending on environment
-
leh
I'm experiencing the same behavior.
-
Pete P.
As a note, FeedEvent has a polymorphic association
belongs_to :source, :polymorphic => true -
Pete P.
Ok, I've found the offending method(sort of)...
Its ActiveRecord::Base#reset_subclasses
I've attached a simple test case which details it. A couple of key points...if you execute all the preparatory statements in the test case(eg, migration and model creation) in a console, the test case will pass. However, if you create appropriate files for the models and migrations, and then load the console and run the subsequent test code, the test case will fail! The plot thickens...
-
Pete P.
The work around(ugh...)
You must explicitly name subclasses in the parent class
#for the example above class ProjectFeedEvent < FeedEvent def self.subclasses [ProjectAddedEvent] end end -
CancelProfileIsBroken
- Tag changed from 2.3.2, cache_classes, inheritance, single, table to 2.3.2, bugmash, cache_classes, inheritance, single, table
-
Peer Allan
verified that the following the steps in the console did duplicate the problem in both master and 2-3-stable. Attempted to verify using the browser when running script/server in development, but was unable to.
Not sure what is going on here. If the classes are all defined in the same model file then the above behaviour occurs. When I separated the model files the SubTest.all used the same SQL before and after the reload of the subclasses.
-
Tarmo Tänav
This is a very old and somewhat known issue [1] due to the development environment not explicitly loading all classes (unlike the production environment) and thus only being aware of the classes that have been referenced during the current request in some way.
A workaround for this is to make the base class model file cause the subclasses to be loaded aswell by listing them at the bottom of the file:
require_association 'subclass1' require_association 'subclass2'This way when the base class is referenced in development mode it also loads all the listed subclasses (which could then load their own subclasses as well should there be a deeper hierarchy).
I can't see any simple fixes to this issue that don't significantly alter the way the development environment works.
-
John Pignata
-1 - I can't reproduce this using 2.3.4
-
Akira Matsuda
-1 couldn't reproduce on 2.3.4
-
CancelProfileIsBroken
- Tag changed from 2.3.2, bugmash, cache_classes, inheritance, single, table to 2.3.2, cache_classes, inheritance, single, table
- State changed from new to stale
Staling because appears to be no longer repro, and no patch available. Please reopen if you have additional info or ideas.
-
Marcin 'swistak' Raczkowski
- Tag changed from 2.3.2, cache_classes, inheritance, single, table to 2.3.2, cache_classes, inheritance, single, table
+1, still happens here on 2.3.4 in dev mode, with class preloading turned off.
Also it's impossible to override the default behaviour with conditions, since it always adds AND table_name.type="Somthing".
-
Jonathan Dance
- Tag changed from 2.3.2, cache_classes, inheritance, single, table to 2.3.5, cache_classes, sti
- I've reproduced this bug in 2.3.5. It has to do with autoloading, so the classes have to be in separate files. I am guessing those trying to reproduce in the past ran the test case in a single file. The workaround does work (defining self.subclasses).
-
Paul Schreiber
- Importance changed from to
I reproduced this problem on 2.3.10 and wrote it up on StackOverflow.
Adding
require_associationdidn't work for me, but explicitly listing the subclasses (per Pete P.) did. -
Neeraj Singh
- State changed from stale to wontfix
This is a well documented issue. I will add a link to the document when I find that.
