Skip to content

Instantly share code, notes, and snippets.

@dbackeus
Created August 16, 2011 13:35
Show Gist options
  • Select an option

  • Save dbackeus/1149078 to your computer and use it in GitHub Desktop.

Select an option

Save dbackeus/1149078 to your computer and use it in GitHub Desktop.
Disappeared parent in child after_destroy
class Parent
include Mongoid::Document
embeds_many :children
before_create :create_child
private
def create_child
children.build
end
end
class Child
include Mongoid::Document
embedded_in :parent
after_destroy :do_something_related_to_parent
private
def do_something_related_to_parent
parent.children # ERROR: undefined method `children' for nil:NilClass
end
end
Parent.create.children.destroy_all # no problem?!
Parent.create.children.first.destroy # error!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment