Created
April 18, 2012 18:33
-
-
Save diminish7/2415658 to your computer and use it in GitHub Desktop.
Proposed change to build_association
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
# Returns a new, unsaved instance of the associated class. +options+ will | |
# be passed to the class's constructor. | |
def build_association(*options, &block) | |
if options.first.is_a?(Hash) && (subclass_name = options.first.with_indifferent_access[klass.inheritance_column]).present? | |
begin | |
subclass = klass.module_eval { compute_type(subclass_name) } | |
raise NameError unless (subclass == klass || subclass.ancestors.include?(klass)) | |
subclass.new(*options, &block) | |
rescue NameError | |
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{klass.name}") | |
end | |
else | |
klass.new(*options, &block) | |
end | |
end |
More commenting ...
Comment comment comment blah blah blah.
And again!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy.