title: Rails ActiveRecord querying the wrong model
body: <p>In my controller in index action:</p>
  
  <pre><code>    @keys = Quran::Ayah.fetch_ayahs(params[:surah], range.first, range.last).map{|k| k.ayah_key}
  
      # @cardinalities = Quran::Surah.first
      @cardinalities = Content::Resource.fetch_cardinality(params[:quran])
  </code></pre>
  
  <p>When I leave these two, I get this in console: </p>
  
  <pre><code>Quran::Ayah Load (0.6ms)  SELECT "quran"."ayah".* FROM "quran"."ayah"  WHERE (quran.ayah.surah_id = '1' AND quran.ayah.ayah_num &gt;= '1' AND quran.ayah.ayah_num &lt;= '5')  ORDER BY quran.ayah.surah_id, quran.ayah.ayah_num
  Content::Resource
    Content::Resource Load (0.6ms)  SELECT "quran"."resource".* FROM "quran"."resource" JOIN content.resource_api_version  using ( resource_id )
  PG::UndefinedTable: ERROR:  relation "quran.resource" does not exist
  LINE 1: SELECT "quran"."resource".* FROM "quran"."resource" JOIN con...
                                           ^
  : SELECT "quran"."resource".* FROM "quran"."resource" JOIN content.resource_api_version  using ( resource_id )
    Rendered bucket/ayat/index.jbuilder (2.3ms)
  </code></pre>
  
  <p>When I comment the <code>@keys</code> line, it works fine: </p>
  
  <pre><code>Content::Resource Load (3.7ms)  SELECT "content"."resource".* FROM "content"."resource" JOIN content.resource_api_version  using ( resource_id )
  </code></pre>
  
  <p>No idea why this is happening? Why is it querying for <code>quran.resource</code> when the model is not that! </p>
  
  <p>Models:</p>
  
  <pre><code>class Content::Resource &lt; ActiveRecord::Base
      extend Content
  
      self.table_name = 'resource'
      self.primary_key = 'resource_id'
  
      belongs_to :author, class_name: 'Content::Author'
      belongs_to :source, class_name: 'Content::Source'
      belongs_to :language, class_name: 'I18n::Language', foreign_key: 'language_code'
  
      # maybe make the block below a polymorphic class, accessible via 'content' or something
      # dunno wth polymorphic relationships really are, so maybe not -- fancy crap not worth a brain cell
      has_many :_image, class_name: 'Quran::Image', foreign_key: 'resource_id'
      has_many :_text, class_name: 'Quran::Text', foreign_key: 'resource_id'
      has_many :_word_font, class_name: 'Quran::WordFont', foreign_key: 'resource_id'
      has_many :_tafsir, class_name: 'Content::Tafsir', foreign_key: 'resource_id'
      has_many :_translation, class_name: 'Content::Translation', foreign_key: 'resource_id'
      has_many :_transliteration, class_name: 'Content::Transliteration', foreign_key: 'resource_id'
      has_one  :_resource_api_version, class_name: 'Content::ResourceAPIVersion', foreign_key: 'resource_id'
  
  
      def self.fetch_cardinality(params_quran)
          Rails.logger.info Content::Resource
          @results = Content::Resource
          .joins('JOIN content.resource_api_version  using ( resource_id )')
          # .select([:sub_type, :cardinality_type, :language_code, :slug, :is_available, :description, :name].map{ |term| "content.resource.#{term}" }.join(', '))
          # .where("content.resource.is_available = 't' AND content.resource.type = 'quran'")
          # .where("content.resource_api_version.v2_is_enabled = 't' ")
          # .where("content.resource.resource_id = ?", params_quran)
          return @results
      end
  end
  
  
  class Quran::Ayah &lt; ActiveRecord::Base
      extend Quran
  
      self.table_name = 'ayah'
      self.primary_key = 'ayah_key'
  
      belongs_to :surah, class_name: 'Quran::Surah'
  
      has_many :words, class_name: 'Quran::Word', foreign_key: 'ayah_key'
  
      has_many :tokens, class_name: 'Quran::Token', through: :words
      has_many :stems, class_name:  'Quran::Stem',  through: :words
      has_many :lemmas, class_name: 'Quran::Lemma', through: :words
      has_many :roots, class_name:  'Quran::Root',  through: :words
  
      has_many :_tafsir_ayah, class_name: 'Content::TafsirAyah', foreign_key: 'ayah_key'
  
      has_many :audio, class_name: 'Audio::File', foreign_key: 'ayah_key'
      has_many :texts, class_name: 'Quran::Text', foreign_key: 'ayah_key'
      has_many :images, class_name: 'Quran::Image', foreign_key: 'ayah_key'
      has_many :glyphs, class_name: 'Quran::WordFont', foreign_key: 'ayah_key'
      has_many :tafsirs, class_name: 'Content::Tafsir', through: :_tafsir_ayah
      has_many :translations, class_name: 'Content::Translation', foreign_key: 'ayah_key'
      has_many :transliterations, class_name: 'Content::Transliteration', foreign_key: 'ayah_key'
  
  
      def self.fetch_ayahs(surah_id, from, to)
          self
          .where("quran.ayah.surah_id = ? AND quran.ayah.ayah_num &gt;= ? AND quran.ayah.ayah_num &lt;= ?", surah_id, from, to)
          .order("quran.ayah.surah_id, quran.ayah.ayah_num")
      end
  end
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I occassionally get this error if it helps:</p>
  
  <blockquote>
    <p>The single-table inheritance mechanism failed to locate the subclass: 'content'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Content::Resource.inheritance_column to use another column for that information.</p>
  </blockquote>