Skip to content

Instantly share code, notes, and snippets.

@weilu
Last active December 26, 2015 04:38
Show Gist options
  • Save weilu/7094220 to your computer and use it in GitHub Desktop.
Save weilu/7094220 to your computer and use it in GitHub Desktop.
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :languages do |t|
t.string :type
end
end
class Language < ActiveRecord::Base
self.store_full_sti_class = false
class Imperative < self
end
class Functional < self
end
end
java = Language::Imperative.new
java.save!
puts java.attributes # {"id"=>1, "type"=>"Imperative"}
java = Language.new type: 'Language::Imperative'
java.save!
puts java.attributes # {"id"=>2, "type"=>"Language::Imperative"}
java = Language.new type: 'Imperative'
# Invalid single-table inheritance type: Imperative is not a subclass of Language (ActiveRecord::SubclassNotFound)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment