I have the following 3 rails classes that are all stored in the same table using rails Single Table inheritance.
class Template < ActiveRecord::Base class ThingTemplate < Template class StockThingTemplate < ThingTemplate
If I have a StockThingTemplate with ID 150 , then I should logically execute this:
ThingTemplate.find(150) =>
And actually it works, sometimes
When it works, it generates the following SQL query:
SELECT * FROM templates WHERE (templates.`id` = 159) AND ( (templates.`type` = 'ThingTemplate') OR (templates.`type` = 'StockThingTemplate' ) )
When it does not work, it generates the following SQL query:
SELECT * FROM templates WHERE (templates.`id` = 159) AND ( (templates.`type` = 'ThingTemplate') )
sql does what it should, but the question is WHY it generates one SQL set once and another set at another time. This is literally the same code.
Notes:
- I'm on the rails 1.2
- I already tried
require 'stock_thing_template' in different places. This either has no effect or causes other problems.
source share