Skip to content

Conversation

jamis
Copy link
Contributor

@jamis jamis commented Jul 22, 2025

Backport to 9.0

Summary

MONGOID-5822 attempted to fix a regression where child callbacks that depended on parent state were no longer invoked if the child had not changed. However, the fix itself introduced an unacceptable performance regression.

This PR restores the earlier functionality, which will break apps that depend on callbacks being invoked on unmodified children (for example, when a child callback depends simply on the parent having changed state).

For now, the correct way to implement that behavior is to explicitly iterate over the children in a parent callback, e.g.:

class Parent
  include Mongoid::Document
  has_many :children
  after_save { children.each(&:parent_changed_callback) }
end

class Child
  include Mongoid::Document
  belongs_to :parent
  
  def parent_changed_callback
    # ...
  end
end

@jamis jamis merged commit bfed4df into mongodb:9.0-stable Jul 23, 2025
61 checks passed
@jamis jamis added the bug Fixes a bug, with no new features or broken compatibility label Jul 23, 2025
@jamis jamis deleted the 5848-revert-MONGOID-5822-9.0 branch July 23, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes a bug, with no new features or broken compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants