From 3e6b2f5d38e0f31db3fb0fcd3bbab92666a0e3e2 Mon Sep 17 00:00:00 2001 From: Pablo Ifran Date: Mon, 22 Oct 2012 09:38:57 -0200 Subject: [PATCH] Changeing some code-styles of the examples & fix a typo on dependent option --- activerecord/lib/active_record/callbacks.rb | 30 +++++++++------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 9626df08aa..188a06e448 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -204,43 +204,37 @@ module ActiveRecord # # Sometimes the code needs that the callbacks execute in a specific order. For example, a +before_destroy+ # callback (log_children in this case) should be executed before the children get destroyed by the - # dependant destroy option. + # dependent destroy option. # # Let's take at the code below: # # class Topic < ActiveRecord::Base - # - # has_many :children, dependant: destroy + # has_many :children, dependent: destroy # # before_destroy :log_children # - # def log_children - # children.each do |child| - # # Some child processing + # private + # def log_children + # # Child processing # end - # end - # # end # # In this case the problem is that when the +before_destroy+ is executed, the children are not available - # because the dependant destroy gets executed first. To solve this issue it is possible - # to use the +prepend+ option on the +before_destroy+ callback. + # because the dependent destroy gets executed first. To solve this issue it is possible to use the + # +prepend+ option on the +before_destroy+ callback. # # class Topic < ActiveRecord::Base - # - # has_many :children, dependant: destroy + # has_many :children, dependent: destroy # # before_destroy :log_children, prepend: true # - # def log_children - # children.each do |child| - # # Some child processing + # private + # def log_children + # # Child processing # end - # end - # # end # - # This way, the +before_destroy+ gets executed before the dependant: destroy is called, and + # This way, the +before_destroy+ gets executed before the dependent: destroy is called, and # the data is still available. # # == Transactions -- GitLab