Dear sirs,
I’m trying to implement a relationship between 2 smart collections, my_collection
and my_subcollection
, but unfortunately I cannot make it work.
So I followed this tutorial: Create a Smart relationship - Documentation
So i implemented the collections as it follows:
### /forest/my_collection.ts
collection('my_collection', {
fields: [
{
field: 'id',
type: 'String',
isReadOnly: true,
isFilterable: true,
isSortable: true,
},
{
field: 'date',
type: 'Date',
isReadOnly: true,
isFilterable: true,
isSortable: true,
},
...
{
field: 'my_subcollection',
type: ['String'],
reference: 'my_subcollection.id',
},
],
actions: [],
});
### /forest/my_subcollection.ts
import { collection } from 'forest-express-sequelize';
collection('my_subcollection', {
fields: [
{
field: 'id',
type: 'String',
isReadOnly: true,
isFilterable: true,
},
{
field: 'my_collection_id',
type: 'String',
isReadOnly: true,
isFilterable: true,
},
],
actions: [],
});
Then I created the route on /routes/my_collection.ts
:
### /routes/my_collection.ts
...
router.get(
'/my_collection/:myCollectionId/relationships/my_subcollection',
async (req, res) => {
...
return res.send({
...serializedMySubcollection,
meta: { count: serializedMySubcollection.length },
});
}
However even if I hardcode it so that I have some serializedMySubcollection
, it won’t work, and it will say the there are no results yet (see screenshot attached).
What should I do to make it work as expected?
Thank you so much in advance for your help.
Best,
Gabriele