Last active
December 26, 2015 04:38
-
-
Save weilu/7094220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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