aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/belongs_to.rb
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2011-11-14 22:57:15 -0800
committerJosh Susser <josh@hasmanythrough.com>2011-11-15 23:32:58 -0800
commit7cba6a37848ba96b4decec885779fb309d71c339 (patch)
treedd1c38690fd0551dd248dfe6005f7532a35e49b1 /activerecord/lib/active_record/associations/builder/belongs_to.rb
parent8d1a2b3ecde5a8745b3eaab4763a71d80ca3441f (diff)
downloadrails-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/belongs_to.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index f6d26840c2..0ca107035f 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -25,14 +25,14 @@ module ActiveRecord::Associations::Builder
name = self.name
method_name = "belongs_to_counter_cache_after_create_for_#{name}"
- model.redefine_method(method_name) do
+ mixin.send(:define_method, method_name) do
record = send(name)
record.class.increment_counter(cache_column, record.id) unless record.nil?
end
model.after_create(method_name)
method_name = "belongs_to_counter_cache_before_destroy_for_#{name}"
- model.redefine_method(method_name) do
+ mixin.send(:define_method, method_name) do
record = send(name)
record.class.decrement_counter(cache_column, record.id) unless record.nil?
end
@@ -48,7 +48,7 @@ module ActiveRecord::Associations::Builder
method_name = "belongs_to_touch_after_save_or_destroy_for_#{name}"
touch = options[:touch]
- model.redefine_method(method_name) do
+ mixin.send(:define_method, method_name) do
record = send(name)
unless record.nil?