diff options
author | Josh Susser <josh@hasmanythrough.com> | 2011-11-14 22:57:15 -0800 |
---|---|---|
committer | Josh Susser <josh@hasmanythrough.com> | 2011-11-15 23:32:58 -0800 |
commit | 7cba6a37848ba96b4decec885779fb309d71c339 (patch) | |
tree | dd1c38690fd0551dd248dfe6005f7532a35e49b1 /activerecord/lib/active_record/associations/builder/has_one.rb | |
parent | 8d1a2b3ecde5a8745b3eaab4763a71d80ca3441f (diff) | |
download | rails-7cba6a37848ba96b4decec885779fb309d71c339.tar.gz rails-7cba6a37848ba96b4decec885779fb309d71c339.tar.bz2 rails-7cba6a37848ba96b4decec885779fb309d71c339.zip |
association methods are now generated in modules
Instead of generating association methods directly in the model
class, they are generated in an anonymous module which
is then included in the model class. There is one such module
for each association. The only subtlety is that the
generated_attributes_methods module (from ActiveModel) must
be forced to be included before association methods are created
so that attribute methods will not shadow association methods.
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/has_one.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_one.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index 88c0d3e90f..2cea8b9805 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -44,18 +44,17 @@ module ActiveRecord::Associations::Builder end def define_destroy_dependency_method - model.send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1) - def #{dependency_method_name} - association(#{name.to_sym.inspect}).delete - end - eoruby + name = self.name + mixin.send(:define_method, dependency_method_name) do + association(name).delete + end end alias :define_delete_dependency_method :define_destroy_dependency_method alias :define_nullify_dependency_method :define_destroy_dependency_method def define_restrict_dependency_method name = self.name - model.redefine_method(dependency_method_name) do + mixin.send(:define_method, dependency_method_name) do raise ActiveRecord::DeleteRestrictionError.new(name) unless send(name).nil? end end |