Please sign in to comment.
Fix creating children in after_* callbacks
Previously creating children in an after_* callback would cause the child's ancestry column to contain just the parent id and not the entire ancestry path. A workaround was to call self.reload in the after_* callback, but this commit makes the process work automatically. The main issue looked to be that the child_ancestry method was using the ancestry path before the save (using _was) which for new records was obviously blank. This revision uses the current value of the parent's ancestry, and adds a child_ancestry_was method to return the old behaviour (with a more descriptive name). The change to update_descendants_with_new_ancestry was due to it relying on the old behaviour. The revised version explicitly replaces the old parent ancestry snippet (using child_ancestry_was) with the new one path.
- Loading branch information...
Showing with 14 additions and 6 deletions.