Feature(s) impacted
I would like to use addExternalRelation
to build a complex one-to-many relationship.
If we were a concert app, I would like to have a relationship between users and their unclaimed concert tickets. “Unclaimed” tickets here would be a ticket with an Email
but no ClaimedAt
field for example. (Using addExternalRelation
might be an XY issue here)
Tickets and users live in two different Sequelize data sources (there are two databases).
Observed behavior
addExternalRelation
needs a schema
to be aware of what data is returned.
Because this is pointing to an existing collection, I would really like to reuse its schema with some Pick
ing on the fields I will project in the body.
Here is some example code:
users.addExternalRelation('UnclaimedTickets', {
schema: { }, // TODO plug the Pick<>ed Tickets schema somehow
dependencies: ['...'],
listRecords(record, context) {
return context.dataSource.getCollection('Tickets').list(
{
conditionTree: { /* one giant mess */ },
},
[/* a few projected fields */],
)
},
})
Is there any way to get the schema from a collection?
Context
- Agent technology: nodejs
- Agent (forest package) name & version: 1.40.1 with sequelize 6.37.3 and sequelize-typescript 2.1.6
- Database type: MSSQL
- Recent changes made on your end if any: Migrating from old agent.