Created
September 5, 2010 19:01
Revisions
-
zerobearing2 revised this gist
Sep 5, 2010 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,6 @@ module EmbeddedCallbacks # bubble callbacks to embedded assocaitions def run_callbacks(*args) # now bubble callbacks down self.associations.each_pair do |name, meta| if meta.association == Mongoid::Associations::EmbedsMany @@ -15,8 +13,7 @@ def run_callbacks(*args) self.send(name).send(:run_callbacks, args) end end super(args) # defer to parent end end -
zerobearing2 created this gist
Sep 5, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # encoding: utf-8 module Mongoid #:nodoc: module Associations #:nodoc: module EmbeddedCallbacks # bubble callbacks to embedded assocaitions def run_callbacks(*args) parent_callback_result = super(args) # defer to parent # now bubble callbacks down self.associations.each_pair do |name, meta| if meta.association == Mongoid::Associations::EmbedsMany self.send(name).each{|doc| doc.send(:run_callbacks, args)} elsif meta.association == Mongoid::Associations::EmbedsOne self.send(name).send(:run_callbacks, args) end end parent_callback_result end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class Photo include Mongoid::Document include Mongoid::Timestamps mount_uploader :image, ImageFileUploader embedded_in :some_model, :inverse_of => :photos validates_presence_of :image end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ class SomeModel include Mongoid::Document include Mongoid::Associations::EmbeddedCallbacks include Mongoid::Timestamps embeds_many :photos end