diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/singular_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/singular_association.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb index f06426a09d..2a4b1c441f 100644 --- a/activerecord/lib/active_record/associations/builder/singular_association.rb +++ b/activerecord/lib/active_record/associations/builder/singular_association.rb @@ -1,19 +1,18 @@ +# This class is inherited by the has_one and belongs_to association classes + module ActiveRecord::Associations::Builder class SingularAssociation < Association #:nodoc: - def valid_options - super + [:remote, :dependent, :counter_cache, :primary_key, :inverse_of, :automatic_inverse_of] - end - - def constructable? - true + def self.valid_options(options) + super + [:remote, :dependent, :counter_cache, :primary_key, :inverse_of] end - def define_accessors + def self.define_accessors(model, reflection) super - define_constructors if constructable? + define_constructors(model.generated_feature_methods, reflection.name) if reflection.constructable? end - def define_constructors + # Defines the (build|create)_association methods for belongs_to or has_one association + def self.define_constructors(mixin, name) mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def build_#{name}(*args, &block) association(:#{name}).build(*args, &block) |