Permalink
Browse files

separate some mutations from reflection construction

  • Loading branch information...
1 parent 69339e5 commit 35f94acf55f0d4dbcba747601434736685e9924f @tenderlove tenderlove committed Aug 1, 2013
@@ -26,6 +26,7 @@ def self.build(model, name, scope, options, &block)
raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
builder = new(model, name, scope, options, &block)
+ builder.define_accessors model.generated_feature_methods
builder.build
end
@@ -49,12 +50,7 @@ def initialize(model, name, scope, options)
end
end
- def mixin
- @model.generated_feature_methods
- end
-
def build
- define_accessors(mixin)
configure_dependency if options[:dependent]
reflection = ActiveRecord::Reflection.create(macro, name, scope, options, model)
Association.extensions.each do |extension|
@@ -23,6 +23,11 @@ def valid_dependent_options
[:destroy, :delete]
end
+ def define_accessors(mixin)
+ super
+ add_counter_cache_methods mixin
+ end
+
private
def add_counter_cache_methods(mixin)
@@ -72,7 +77,6 @@ def belongs_to_counter_cache_after_update(association, reflection)
def add_counter_cache_callbacks(reflection)
cache_column = reflection.counter_cache_column
- add_counter_cache_methods mixin
association = self
model.after_create lambda { |record|

0 comments on commit 35f94ac

Please sign in to comment.