Model's Dependency

The model's dependency has been introduced on NexoPOS 4.7.x and that mainly helps to prevent resources deletion that is required by other models. Technically this means that before deleting a category NexoPOS will check if there is a product assigned to that category to prevent the deletion.

This guide explains how the model dependency works on NexoPOS.

Declaring Dependency

This should be made on the model itself. We state on the model which other model has a dependency on him. A model might be dependency on many other models. Every dependency should be clearly defined to prevent deletion.

To declare a dependency, we need to declare a protected property named "isDependencyFor" like this.

That property accepts as key the model class which depends on the current model and the configuration as the value.

Here are the supported values for each dependency:

  • local_name: Actual attribute to pull the Model name. That will be used for throwing an understandable error.
  • local_index: Is the actual attribute that is used to compare on dependent models. Usually the value is "id".
  • foreign_name: Attribute of the found dependency to pull it's name. That will also be used to thrown an understandable error.
  • foreign_index: That is the attribute that match the local index, used for identifying dependency.

As our model is "Category", and we declared that to be a dependency for "Product". Here is the final form of our configuration.

While trying to delete, you'll end up with the following error.

In case a dependency has been found.