User Tools

Site Tools


t1.8_validating_datarecord_objects_and_some_notes_about_deletions_datarecord

Datarecord validation

This chapter is a little intermezzo and you can continue to the next chapter if you are eager to keep building the application.

In order to keep performance of Platform at a maximum, internal object integrity isn't performed when using Datarecord objects, so if you forget anything in the definition or link something wrong together, this will most likely cause an error. For debug purposes Datarecord therefore contains a function called renderIntegrityCheck which will validate your object and display if any problems are detected. You can create the following script to test the integrity of our two new objects:

integrity_check.php
Department::renderIntegrityCheck();
Employee:renderIntegrityCheck();

When running this, you will actually receive an error:

Remote class People\Department doesn't list this as a referer or dependent class, even though we refer in field: department_ref

Platform is able to keep track on references between objects, but in order for this to work, the class that is being referred needs to be aware of this. So the problem is, that we have made a reference from Employee to Department, but we need to make a note of this in the Department object.

We do this by adjusting the Department class as follows:

department.php
  ...
  protected static $referring_classes = array(
    'People\\Employee'
  );

This informs the Department class that we are referring it from the Employee object.

Referring vs depending

Note that there is another array called $depending_classes where we also could have added the class reference.

Both of these comes into play when a department is deleted. When the Employee class is listed as referring, Platform will just remove all references from the employees to departments that are deleted, but keep the employees.

If the Employee class was listed as depending instead, Platform would outright delete all employees referring to department that are deleted as it is then assumed that an employee couldn't exist without its department.

That's it for the intermezzo.

t1.8_validating_datarecord_objects_and_some_notes_about_deletions_datarecord.txt · Last modified: 2021/03/10 21:15 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki