diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-08-10 16:38:51 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-08-10 17:45:07 +0100 |
commit | 6bb8afb45e0fd9243a487e12a0988ac6ea9916bc (patch) | |
tree | 2310fea1d758bf62840145eab9f7b46c3f7e52a3 /activerecord/lib/active_record/associations/builder/has_one.rb | |
parent | 825c05d491205840438d3ec346bd3c12e5291a93 (diff) | |
download | rails-6bb8afb45e0fd9243a487e12a0988ac6ea9916bc.tar.gz rails-6bb8afb45e0fd9243a487e12a0988ac6ea9916bc.tar.bz2 rails-6bb8afb45e0fd9243a487e12a0988ac6ea9916bc.zip |
DRY up handling of dependent option
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/has_one.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_one.rb | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index bef909a882..0da564f402 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -1,4 +1,3 @@ - module ActiveRecord::Associations::Builder class HasOne < SingularAssociation #:nodoc: def macro @@ -15,27 +14,12 @@ module ActiveRecord::Associations::Builder !options[:through] end - def build - reflection = super - configure_dependency unless options[:through] - reflection - end - def configure_dependency - if dependent = options[:dependent] - validate_dependent_option [:destroy, :delete, :nullify, :restrict, :restrict_with_error, :restrict_with_exception] - - name = self.name - mixin.redefine_method(dependency_method_name) do - association(name).handle_dependency - end - - model.before_destroy dependency_method_name - end + super unless options[:through] end - def dependency_method_name - "has_one_dependent_for_#{name}" + def valid_dependent_options + [:destroy, :delete, :nullify, :restrict, :restrict_with_error, :restrict_with_exception] end end end |