Skip to content
  • Tekin Suleyman's avatar
    5a3e34ed
    Ensure Contextual validations fire on associations · 5a3e34ed
    Tekin Suleyman authored
    If a custom validation context is used, the validations on dependent
    association records should fire regardless of whether those record have
    `changed_for_autosave?` or not as the use of a custom validation context
    increases the chance that validations for the context will be different
    to those from when the record was first saved.
    
    6ea80b61 changed the autosave behaviour for single associations such that
    validations would only fire on an associated record if the record was
    `changed_for_autosave?`. This brought the behaviour inline with that for
    collection associations, but introduce a regression in that validations
    would no longer fire on dependent associations, even when using a custom
    validation context.
    
    This change updates the behaviour for both single and collection
    associations.
    
    This commit also updates another related regression test that became a
    potential false-positive when 6ea80b61 was merged. The original test was
    written to protect against non-custom validations firing on associations
    (see #14106). At the time validations on autosaving singular
    associations would always fire, even when the association was not dirty,
    whereas after 6ea80b61 the validations only fire if the association is
    dirty. This update to the test makes the association record dirty to
    ensure the validations will fire so that the code responsible for
    excluding non-custom contexts is correctly exercised.
    5a3e34ed
    Ensure Contextual validations fire on associations
    Tekin Suleyman authored
    If a custom validation context is used, the validations on dependent
    association records should fire regardless of whether those record have
    `changed_for_autosave?` or not as the use of a custom validation context
    increases the chance that validations for the context will be different
    to those from when the record was first saved.
    
    6ea80b61 changed the autosave behaviour for single associations such that
    validations would only fire on an associated record if the record was
    `changed_for_autosave?`. This brought the behaviour inline with that for
    collection associations, but introduce a regression in that validations
    would no longer fire on dependent associations, even when using a custom
    validation context.
    
    This change updates the behaviour for both single and collection
    associations.
    
    This commit also updates another related regression test that became a
    potential false-positive when 6ea80b61 was merged. The original test was
    written to protect against non-custom validations firing on associations
    (see #14106). At the time validations on autosaving singular
    associations would always fire, even when the association was not dirty,
    whereas after 6ea80b61 the validations only fire if the association is
    dirty. This update to the test makes the association record dirty to
    ensure the validations will fire so that the code responsible for
    excluding non-custom contexts is correctly exercised.
Loading