title: Tableless model with ActiveRecord associations in Rails 3.2
body: <p>My application configuration includes some values which need to be used in AR relationships. I'm aware this is an odd and potentially criminal thing to attempt, but I need to maintain the configuration as a textfile, and I honestly think I have a good case for a tableless model. Unfortunately I'm having trouble convincing AR (Rails 3.2) not to look for the table. My tableless model: </p>
  
  <pre><code>class Tableless &lt; ActiveRecord::Base
  
    def self.table_name
        self.name.tableize
    end
  
    def self.columns
      @columns ||= [];
    end
  
    def self.column(name, sql_type = nil, default = nil, null = true)
      columns &lt;&lt; ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
    end
  
    def self.columns_hash
      @columns_hash ||= Hash[columns.map { |column| [column.name, column] }]
    end
  
    def self.column_names
      @column_names ||= columns.map { |column| column.name }
    end
  
    def self.column_defaults
      @column_defaults ||= columns.map { |column| [column.name, nil] }.inject({}) { |m, e| m[e[0]] = e[1]; m }
    end
  
    def self.descends_from_active_record?
      return true
    end
  
    def persisted?
      return false
    end
  
    def save( opts = {} )
      options = { :validate =&gt; true }.merge(opts)
      options[:validate] ? valid? : true
    end
  end
  </code></pre>
  
  <p>This is extended by the actual model: </p>
  
  <pre><code>class Stuff &lt; Tableless
  
    has_many :stuff_things
    has_many :things, :through =&gt; :stuff_things
  
    column :id, :integer
    column :name, :string
    column :value, :string
  
    def initialize(attributes = {})
      attributes.each do |name, value|
        send("#{name}=", value)
      end
    end
  end
  </code></pre>
  
  <p>This is all based on code found <a href="https://stackoverflow.com/questions/7275496/tableless-model-in-rails-3-1">here on SO</a> and <a href="https://gist.github.com/1101257" rel="nofollow noreferrer">elsewhere</a>, but alas, I get <strong>SQLException: no such table: stuffs:</strong> Any clues any one? </p>