Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-71086

Persistent classes could self-validate record fields

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.10.2
    • Fix Version/s: None
    • Component/s: Libraries
    • Labels:
    • Affected Branches:
      MOODLE_310_STABLE

      Description

      We use this pattern often in Workplace (where we make frequent use of \core\persistent) - it's often helpful for us to validate record fields in the persistent constructor, as follows:

              if ($record) {
                  $record = (object)array_intersect_key((array)$record, static::properties_definition());
              }
      

      Creating this task in case it would be helpful to move this to the base persistent class

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            pholden Paul Holden
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: