LSPS documentation logo
LSPS Documentation
Validating a Related Record

To validate related records of a record (cascade validation), do the following:

  1. Define the constraints for the related record.
  2. Define the constraint that will trigger the validation of the related records:
    • If the relationship is to-one:
      1. Set the record property to the relevant property path, for example, Book.author.
      2. Set the constraint type to RecordValidity.
    • If the relationship is to-many:
      1. Set the record property to the relevant property path, for example, Author.books.
      2. Set the constraint type to RecordCollectionValidity.

        Important: Make sure the validation does not result in infinite recursive validation (the relationship record does not validate the parent record).

  3. Call the validate() function on the main record.

Example:

cascadeValidationDataModel.png
Underlying data model
cascadeValidationConstraints.png
Constraints

def Author author := new Author(books -> {new Book(title -> null)}, name -> null); validate (author, null, null, null); Since the Author.books.RecordCollectionValidity constraint defines RecordCollectionValidity, the validate() checks also the created book constraints and violations on the constraints Author.name.NotNull and Book.title.NotNull are returned.