Computed foreign keys
Last updated
Last updated
This is the official documentation of the @forestadmin/agent
Node.js agent.
You may want to create a relationship between 2 Collections, but you don't have a foreign key that is ready to use to connect them.
To solve that use case, you should use both and relationships.
This is done with the following steps:
create a new Field containing a foreign key,
make the Field filterable for the In
operator (see as to why this is required),
create a relation using it.
We have 2 Collections: Customers
and Messages
, linked together by a one-to-many
relationship.
We want to create a ManyToOne
relationship with the last message sent by a given customer.
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.