When using primitive type fields, Forest Admin supports declaring a validation clause, which will be imported into the UI of the admin panel to validate records before creating/updating them.
The API for validation is the same as with condition trees, besides the fact that there is no "field" entry.
You can declare relationships at the collection level, but that means that the data source you are making is responsible for handling them.
This will work out of the box for data sources using the "local-cache" strategy, however, please read "Intra-data source Relationships", before starting with the "query translation" strategy.
Examples
<?php
use ForestAdmin\AgentPHP\DatasourceToolkit\Collection;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Contracts\DatasourceContract;
use ForestAdmin\AgentPHP\DatasourceToolkit\Schema\ColumnSchema;
use ForestAdmin\AgentPHP\DatasourceToolkit\Schema\Relations\ManyToManySchema;
use ForestAdmin\AgentPHP\DatasourceToolkit\Schema\Relations\ManyToOneSchema;
class MovieCollection extends Collection
{
public function __construct(DatasourceContract $datasource)
{
// [...]
$this->addField('director', new ManyToOneSchema(
foreignKey: 'directorId',
foreignKeyTarget: 'id',
foreignCollection: 'People'
));
$this->addField('actors', new ManyToManySchema(
originKey: 'movieId',
originKeyTarget: 'id',
foreignKey: 'actorId',
foreignKeyTarget: 'id',
foreignCollection: 'People',
throughCollection: 'ActorsOnMovies'
));
Typing
The typing system for relationships is the same as the one used when declaring jointures in the agent customization step.