Last active
August 29, 2015 14:18
-
-
Save richpeck/9971036568633cdb0422 to your computer and use it in GitHub Desktop.
ActiveSupport::Concern
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
#lib/active_record_extension.rb | |
module ActiveRecordExtension #-> http://stackoverflow.com/questions/2328984/rails-extending-activerecordbase | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :store_base_sti_class | |
self.store_base_sti_class = true | |
end | |
end | |
# include the extension | |
ActiveRecord::Base.send(:include, ActiveRecordExtension) | |
### | |
module AddPolymorphic | |
extend ActiveSupport::Concern | |
included do #-> http://stackoverflow.com/questions/28214874/overriding-methods-in-an-activesupportconcern-module-which-are-defined-by-a-cl | |
define_method :replace_keys do |record=nil| | |
super(record) | |
owner[reflection.foreign_type] = ActiveRecord::Base.store_base_sti_class ? record.class.base_class.name : record.class.name | |
end | |
end | |
end | |
ActiveRecord::Associations::BelongsToPolymorphicAssociation.send(:include, AddPolymorphic) | |
#### |
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
#config/initializers/sti_base.rb | |
require "active_record" | |
require "active_record_extension" | |
ActiveRecord::Base.store_base_sti_class = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment