-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 4.0.0 final, 5.0.1, 5.0.0, 5.0.2
-
Component/s: None
-
None
before_add and after_add callbacks get executed when a child calls the parent for the first time in a has_many relation.
band.rb
class Band include Mongoid::Document has_many :albums, before_add: :do_some_stuff, after_add: :notify_followers def do_some_stuff(album) puts "Doing some stuff" end def notify_followers(album) puts "Notifying followers" end end
album.rb
class Album
include Mongoid::Document
belongs_to :band
end
album = Album.first album.band Doing some stuff Notifying followers => #<Band _id: ... > album.band => #<Band _id: ... >
I checked embedded_in and has_and_belongs_to_many relations with these callbacks, and they don't have this behaviour.
- is duplicated by
-
MONGOID-3565 after_add event fired when document is loaded from database
- Closed