ActiveRecord running different queries in production?

I have a class hierarchy looks like this:

class Post < ActiveRecord::Base; end class Project < Post; end class ProjectDesignWall < Project; end

There's a controller that fetches data like so:

@projects = Project.find(:all, :include => [:project_image_photos,:user])

In development, this runs the following query, straight from the logs:

SELECT * FROM `posts` WHERE ( (`posts`.`type` = 'Project' ) ) ORDER BY originally_created_at DESC

However, as soon as it's run in production mode, even with the same database and data, it results in the following query:

SELECT * FROM `posts` WHERE ( (`posts`.`type` = 'Project' OR `posts`.`type` = 'ProjectDesignWall' ) ) ORDER BY originally_created_at DESC

Does anyone know why this is happening, and is there any way to get it to at least behave consistantly, if not outright fix the problem?


There is an open ticket for this bug here:

The solution is listed at the bottom of this ticket:

To quote:

You must explicitly name subclasses in the parent class

class ProjectFeedEvent < FeedEvent

def self.subclasses


Part of the reason this issue has been around for a while and has not received much attention is that STI is not commonly necessary in Rails. Most contributors to Rails have decided not to use it in their own projects and therefore do not put time into making sure that it is well supported. Here's a blurb that briefly explains why you should not use it and suggests an alternative:

My own personal experiences using STI at my company was that is seemed very useful at first, but as time went on we determined that we simply didn't need it enough to warrant the complexity. Since then, our project has grown dramatically and we have not missed it at all.

Because in production all your classes are loaded at once. When all the classes are loading it realises that ProjectDesignWall is a subclass of Project thus gathers all of them.

Category:ruby on rails Time:2009-04-01 Views:1

Related post

  • ActiveRecord "SHOW TABLES" queries 2011-07-15

    I'm using Rails 2.3 for my project, with Resque for processing background tasks. ActiveRecord usually does a "SHOW TABLES" and "SHOW FIELDS FROM" query the first time you use any model, then caches it. My issue is that Resque forks a new process for

  • Problem running RoR app in production environment 2010-03-12

    Have an app that has "listings" - think classified ads - and each listing has a list of tags. The following code fails when I run the app in production mode, but works fine under development mode uninitialized constant ActiveRecord::Acts::Taggable::I

  • Log SQL queries in production? 2010-06-04

    I'm having a dilemma on whether or not to log SQL queries in production as well. I don't know how slow writing files is in PHP. Probably some benchmarks could give some answers, but I wanted to see what you guys think before. What does or does not ma

  • solr RequestHandler to run multiple queries in a batch 2011-05-27

    solr RequestHandler to run multiple queries in a batch PleaSE help me... how to ru the multiple query at one shot and it should return the result.. Thank in advance --------------Solutions------------- Query batching is a pending issue. You can do th

  • Running MDX Queries on TFS 2012-02-22

    I would like to run MDX Queries on the TFS Warehouse Database. I would like to query about the code churn, code coverage, ... and many other metrics. Is there an easy way of creating those MDX queries? How can I achieve this? I want to run those quer

  • How do I run range queries on LDAP 2010-01-15

    I am trying to retrieve data about groups on LDAP. As I need to paginate results, I need to run range queries. My setup uses JNDI to connect to LDAP. I am trying to run this query (&(objectclass=group)(range=1-500)) What am I doing wrong? I know

  • how to show running mysql queries in php 2010-01-19

    I have an overflow memory usage problem and I need to scan all my scripts. My question is how can I show a list of running mysql queries in php? --------------Solutions------------- You can rename the original mysql_query function and write your own

  • Codeigniter: Combining activeRecord with manual queries? 2010-06-06

    I've though a bit about the activerecord vs. manual queries in Codeigniter. ActiveRecord is awesome when it's all about standard queries and holds development time really low. However, when there's a need to add some complexity to the queries, the Ac

  • Run 2 queries at the same time on Oracle SQL Developer? 2010-07-13

    I need to retrieve quite a bit of data from our oracle DB and to do so I need to run 20+ queries. Is there any way to run more than one query at a time on the same connection? I tried using / to separate the queries, but that simply opens multiple ta

  • DataReader already open error when trying to run two queries 2010-11-10

    I have a couple of queries that I need to run one to a linked server and one not like this Dim InvestorLookup As String = "DECLARE @investor varchar(10), @linkedserver varchar(25), @sql varchar(1000) " InvestorLookup += "SELECT @investor = '" & i

  • Running mutiple queries with mysqli 2010-11-23

    Working on a currency conversion service, using Bloomberg to get live rates of currencies (using USD as base rate). I can get all of the rates from bloomberg no problem, just when inserting them into the database (for cache and retrieving later) it s

  • Can LINQPad run SQL Queries on OData? 2010-12-08

    I can run LINQ queries successfully to retrieve data from OData providers. I'm not able to run SQL queries with OData. Since I'm behind who knows how many firewalls at work, I'm not sure if it's LINQPad or a firewall issue of some sort. -------------

  • LINQ (to objects) , running several queries over the same IEnumerable? 2011-01-31

    Is it somehow possible to chain together several LINQ queries on the same IEnumerable ? Some background, I've some files, 20-50Gb in size, they will not fit in memory. Some code parses messages from such a file, and basically does : public IEnumerabl

  • Run SPARQL Queries on Drupal Nodes 2011-05-03

    Is there a way to run SPARQL queries on the RDF generated for certain type of nodes? E.g., if I have a content type called People described by the FOAF ontology, can I run SPARQL queries on nodes of type People? --------------Solutions------------- I

  • Python : run multiple queries in parallel and get the first finished 2011-07-01

    I try to create a Python script that performs queries to multiple sites. The script works well (I use urllib2) but just for one link. For multiples sites, I make multiple requests one after the other but it is not very powerful. What is the ideal sol

  • PHP MySQL Run Two Queries in one Connection? 2011-07-28

    Is it possible to run two queries inside of one connection. What I am doing is I am populating a form with profile data. But then I need to populate two drop downs from a database that contains the values. I have included how I have it setup but my f

  • Running Multiple Queries through Shell Script 2011-09-02

    I have 6 MySQL Queries and I need to run queries via shell script and the result should get imported in CSV file I know how to run a single MYSQL query through shell script but how to run multiple queries throught Shell script. --------------Solution

  • EclipseLink JPA: Can I run multiple queries from one builder? 2011-09-03

    I have a method that builds and runs a Criteria query. The query does what I want it to, specifically it filters (and sorts) records based on user input. Also, the query size is restricted to the number of records on the screen. This is important bec

  • Run SQL Queries from Visual Studio 2010 Test Suite when running Load Tests 2011-11-03

    I am newbie to Visual Studio 2010 test suite. I have created a load test to perform some stress testing on the wcf services where I am gradually increasing the number of users. These services perform some processing of the data and store the result i

Copyright (C), All Rights Reserved.

processed in 0.437 (s). 13 q(s)