Created
August 16, 2011 13:35
-
-
Save dbackeus/1149078 to your computer and use it in GitHub Desktop.
Disappeared parent in child after_destroy
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 characters
| 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