diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/association.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index bbc1c20f60..297b7ce6d3 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -14,11 +14,13 @@ module ActiveRecord::Associations::Builder class Association #:nodoc: class << self attr_accessor :valid_options + attr_accessor :extensions end self.valid_options = [:class_name, :foreign_key, :validate] + self.extensions = [] - attr_reader :model, :name, :scope, :options, :reflection + attr_reader :model, :name, :scope, :options def self.build(*args, &block) new(*args, &block).build @@ -48,15 +50,15 @@ module ActiveRecord::Associations::Builder @model.generated_feature_methods end - include Module.new { def build; end } - def build validate_options define_accessors configure_dependency if options[:dependent] - @reflection = model.create_reflection(macro, name, scope, options, model) - super # provides an extension point - @reflection + reflection = ActiveRecord::Reflection.create(macro, name, scope, options, model) + Association.extensions.each do |extension| + extension.build @model, reflection + end + reflection end def macro @@ -64,13 +66,13 @@ module ActiveRecord::Associations::Builder end def valid_options - Association.valid_options + Association.valid_options + Association.extensions.map(&:valid_options).flatten end def validate_options options.assert_valid_keys(valid_options) end - + # Defines the setter and getter methods for the association # class Post < ActiveRecord::Base # has_many :comments |