From ecaf728774aa5f4232cc17532272408f9a9819b7 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sat, 15 Sep 2012 12:00:27 +0400 Subject: Improve documentation about :dependent and callbacks. Fixes #3458. --- activerecord/lib/active_record/associations.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index d6b8552e6e..203ddd17c7 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -949,6 +949,11 @@ module ActiveRecord # is done. For more information, see the documentation for this option on the different # specific association types. When no option is given, the behaviour is to do nothing # with the associated records when destroying a record. + # + # Note that :dependent is implemented using Rails' callback + # system, which works by processing callbacks in order. Therefore, other + # callbacks declared either before or after the :depenent option + # can affect what it does. # # === Delete or destroy? # -- cgit v1.2.3 From 5853f6223c808f05854745ec1199e442680afd3f Mon Sep 17 00:00:00 2001 From: Henrik N Date: Sun, 16 Sep 2012 12:22:36 +0200 Subject: Doc typo: depenent -> dependent; trailing ws. --- activerecord/lib/active_record/associations.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 203ddd17c7..577b87e708 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -949,10 +949,10 @@ module ActiveRecord # is done. For more information, see the documentation for this option on the different # specific association types. When no option is given, the behaviour is to do nothing # with the associated records when destroying a record. - # + # # Note that :dependent is implemented using Rails' callback # system, which works by processing callbacks in order. Therefore, other - # callbacks declared either before or after the :depenent option + # callbacks declared either before or after the :dependent option # can affect what it does. # # === Delete or destroy? -- cgit v1.2.3 From efef82ffb0c3b5c3c2092f56793cd5940e9526cd Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 19 Sep 2012 00:47:38 -0500 Subject: fix :nodoc:s in AR::Timestamp [ci skip] --- activerecord/lib/active_record/timestamp.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index c32e0d6bf8..bf95ccb298 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -40,13 +40,13 @@ module ActiveRecord config_attribute :record_timestamps, instance_writer: true end - def initialize_dup(other) + def initialize_dup(other) # :nodoc: clear_timestamp_attributes end private - def create #:nodoc: + def create if self.record_timestamps current_time = current_time_from_proper_timezone @@ -60,7 +60,7 @@ module ActiveRecord super end - def update(*args) #:nodoc: + def update(*args) if should_record_timestamps? current_time = current_time_from_proper_timezone @@ -89,19 +89,19 @@ module ActiveRecord timestamp_attributes_for_create_in_model + timestamp_attributes_for_update_in_model end - def timestamp_attributes_for_update #:nodoc: + def timestamp_attributes_for_update [:updated_at, :updated_on] end - def timestamp_attributes_for_create #:nodoc: + def timestamp_attributes_for_create [:created_at, :created_on] end - def all_timestamp_attributes #:nodoc: + def all_timestamp_attributes timestamp_attributes_for_create + timestamp_attributes_for_update end - def current_time_from_proper_timezone #:nodoc: + def current_time_from_proper_timezone self.class.default_timezone == :utc ? Time.now.utc : Time.now end -- cgit v1.2.3 From 79cbfc8290f08212faecdb32cea585c435091e87 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 21 Sep 2012 12:58:14 +0300 Subject: Add extra note about :dependent => :destroy. Callbacks may interfere with each other. --- activerecord/lib/active_record/associations.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 577b87e708..d8ab039cec 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1100,7 +1100,10 @@ module ActiveRecord # Specify the method that returns the primary key used for the association. By default this is +id+. # [:dependent] # Controls what happens to the associated objects when - # their owner is destroyed: + # their owner is destroyed. Note that these are implemented as + # callbacks, and Rails executes callbacks in order. Therefore, other + # similar callbacks may affect the :dependent behavior, and the + # :dependent behavior may affect other callbacks. # # * :destroy causes all the associated objects to also be destroyed # * :delete_all causes all the asssociated objects to be deleted directly from the database (so callbacks will not execute) -- cgit v1.2.3