@forestadmin-experimental/plugin-filtered-relationship
v2.1.0
Published
The plugin allows you to create a filtered oneToMany relationship.
Downloads
190
Keywords
Readme
The plugin allows you to create a filtered oneToMany relationship.
import { createAgent } from '@forestadmin/agent';
import { Schema } from './typings';
import filteredRelationship from '@forestadmin-experimental/plugin-filtered-relationship';
import type { FilteredOneToManyOptions } from '@forestadmin-experimental/plugin-filtered-relationship';
await createAgent<Schema>(Options)
.addDataSource(DataSourceOptions)
.customizeCollection('plan', usersCollection => {
collection.use<FilteredOneToManyOptions<Schema, 'subscription'>>(filteredRelationship, {
relationName: 'activeSubscriptions',
foreignCollection: 'subscription',
handler: (id, context) => ({
aggregator: 'And',
conditions: [
{ field: 'planId', operator: 'Equal', value: id },
{ field: 'finishedAt', operator: 'Missing' },
],
}),
});
})