Do not validate all children when parent is persisted by default

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • None
    • Ruby Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Starting from Mongoid 9 and some of 8.x versions we have a combination of features that causes a performance degradation (compared to 7.x):

      1. belongs_to associations are now required by default, and this is done with a validation.
      2. When a document is persisted, we validate all its associations, including those that were not changed.

      This means that when a parent document is saved, validations run on all its children, via has_many and embeds_many.
      We believe this behaviour is an overkill for a default. On the other hand, we can imagine
      a customer may want to ensure data consistency even with a performance penalty.

      Therefore, in 9.x we should introduce a feature flag validate_all_children that is
      set to true by default. We filp this flag to false in 10.x.

      When the flag is set to false we have the current behavior - slow but everything
      is validated. When true, we get back to 7.x behaviour, and validate only children
      that are new or changed.

            Assignee:
            Unassigned
            Reporter:
            Dmitry Rybakov
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: