Connecting collections without having a shared identifier
You have 2 Collections and both contain users: one comes from your database, and the other one is connected to the CRM that your company uses.
There is no common id between them that can be used to tell Forest Admin how to link them together, however, both Collections have firstName, lastName, and birthDate fields, which taken together, are unique enough.
useForestAdmin\AgentPHP\DatasourceCustomizer\CollectionCustomizer;useForestAdmin\AgentPHP\DatasourceCustomizer\Decorators\Computed\ComputedDefinition;useForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\ConditionTree\Operators;useForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\Aggregation;useForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\Filters\Filter;useForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\Filters\PaginatedFilter;useForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\ConditionTree\ConditionTreeFactory;useForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\Projection\Projection;/** * Concatenate firstname, lastname and birthData to make a unique identifier * and ensure that the new field is filterable */$createFilterableIdentityField =function (CollectionCustomizer $collection) {// Create foreign key on the collection from the database $collection->addField('userIdentifier',newComputedDefinition( columnType: 'String', dependencies: ['firstName','lastName','birthDate'], values: fn($users) => array_map(fn($u) => $u['firstName'] .'/'. $u['lastName'] .'/'. $u['birthDate'] , $users), ));// Implement 'In' filtering operator (required) $collection->replaceFieldOperator('userIdentifier',Operators::IN,fn ($values) => ['aggregator'=>'Or','conditions'=>array_map(fn ($value) => ['aggregator'=>'And','conditions'=> [ ['field'=>'firstName','operator'=>Operators::EQUAL,explode('/', $value)[0]], ['field'=>'lastName','operator'=>Operators::EQUAL,explode('/', $value)[1]], ['field'=>'birthDate','operator'=>Operators::EQUAL,explode('/', $value)[2]], ] ]), ]);};/** Create relationship between databaseUsers and crmUsers */$createRelationship =function (CollectionCustomizer $collection) { $collection->addOneToOneRelation( name:'userFromCrm', foreignCollection:'crmUsers', originKey:'userIdentifier', originKeyTarget:'userIdentifier',);};/** Create relationship between crmUsers and databaseUsers */$createInverseRelationship =function (CollectionCustomizer $collection) { $collection->addManyToOneRelation( name:'userFromDatabase', foreignCollection:'databaseUsers', foreignKey:'userIdentifier', foreignKeyTarget:'userIdentifier',);};$forestAgent->customizeCollection('databaseUsers', $createFilterableIdentityField)->customizeCollection('crmUsers', $createFilterableIdentityField)->customizeCollection('databaseUsers', $createRelationship)->customizeCollection('crmUsers', $createInverseRelationship);