aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2011-11-27 11:22:12 -0800
committerJosh Susser <josh@hasmanythrough.com>2011-11-27 11:22:12 -0800
commit61bcc318c865289d215e8e19618b9414bd07d1e8 (patch)
tree1bc644f4152dc4315d8490b099c24abc2815088c /activerecord/lib/active_record/associations
parent9cdf33af0bc46fde1ad50346b8271251c2b4aa69 (diff)
downloadrails-61bcc318c865289d215e8e19618b9414bd07d1e8.tar.gz
rails-61bcc318c865289d215e8e19618b9414bd07d1e8.tar.bz2
rails-61bcc318c865289d215e8e19618b9414bd07d1e8.zip
use GeneratedFeatureMethods module for associations
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb8
-rw-r--r--activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb12
2 files changed, 13 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index 686db0725d..3534e037b7 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -6,7 +6,7 @@ module ActiveRecord::Associations::Builder
# Set by subclasses
class_attribute :macro
- attr_reader :model, :name, :options, :reflection, :mixin
+ attr_reader :model, :name, :options, :reflection
def self.build(model, name, options)
new(model, name, options).build
@@ -14,8 +14,10 @@ module ActiveRecord::Associations::Builder
def initialize(model, name, options)
@model, @name, @options = model, name, options
- @mixin = Module.new
- @model.__send__(:include, @mixin)
+ end
+
+ def mixin
+ @model.generated_feature_methods
end
def build
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
index f3391eba13..30fc44b4c2 100644
--- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
+++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
@@ -15,10 +15,14 @@ module ActiveRecord::Associations::Builder
def define_destroy_hook
name = self.name
- mixin.send(:define_method, :destroy_associations) do
- association(name).delete_all
- super()
- end
+ model.send(:include, Module.new {
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def destroy_associations
+ association(#{name.to_sym.inspect}).delete_all
+ super
+ end
+ RUBY
+ })
end
# TODO: These checks should probably be moved into the Reflection, and we should not be