Skip to content

Commit

Permalink
before_save and after_save execute on root document save
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Sep 22, 2009
1 parent ac04793 commit e068e43
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/mongoid/document.rb
Expand Up @@ -9,12 +9,8 @@ class Document #:nodoc:
attr_reader :attributes, :parent

define_callbacks \
:after_create,
:after_save,
:after_validation,
:before_create,
:before_save,
:before_validation
:before_save

class << self

Expand Down Expand Up @@ -139,11 +135,10 @@ def parent=(document)
# document is embedded within another document, or is multiple levels down
# the tree, the root object will get saved, and return itself.
def save
run_callbacks(:before_save)
if @parent
run_callbacks(:after_save)
@parent.save
else
run_callbacks(:before_save)
collection.save(@attributes)
run_callbacks(:after_save)
return self
Expand Down

0 comments on commit e068e43

Please sign in to comment.