提交 3e6b2f5d 编写于 作者: P Pablo Ifran

Changeing some code-styles of the examples & fix a typo on dependent option

上级 d4db0951
......@@ -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 <tt>dependant: destroy</tt> is called, and
# This way, the +before_destroy+ gets executed before the <tt>dependent: destroy</tt> is called, and
# the data is still available.
#
# == Transactions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册