No items found for related collection

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

Hello @Gabriele,

Thanks for your message and welcome to our community! :raised_hands:

Could you please share what it the route called when trying to access to the My subcollections related data (by going to your Network tab in your browser console)?

Thanks!

Here it is: https://app.forestadmin.com/lottie-animations/error_no_match-0d24bc6bf4da03f98bad258a8c63d5e7.json

That’s the only one as far as I can see (apart from 3rd party tools).

@Gabriele,
Thanks for your prompt reply.

Muhm no, that’s not the one that’s interesting here :thinking:

Should be something like this:
https://[name-of-your-agent-api-endpoint]/forest/my_collection/[my-collection-id]/relationships/my_subcollection.

Can’t you see this route at all?
(You can try for instance, when being all your related data page, to clean up the network tab and then click on the search bar and press enter. It should retrigger a call to the data).

And out of curiosity: why did you call the collection under my_subcollection file reconciled_transaction? If you call it my_subcollection, does it change anything?

Thanks.

@anon34731316 sorry, I’ve actually changed the name of the methods, but kept exactly the same structure.

Anyway, if I click on the sub collection, no other request is done apart from the one I mentioned, but the url changes to something ending like this: data/my_collection/index/record/my_collection/1/has-many/my_collection-my_subcollection .

I also tried to map the route like this, but with no good results.

If I reload the page, some HTTP requests are performed:

That’s everything I get!

Hi @Gabriele,

If you put a console.log('ROUTE fetch subCollection') inside the route implementation, can you see it in your server log while you browse the sub-collection?

Also, can you please you this tutorial and share the resulting link?
This will allow us seeing which endpoints are called by your browser.

Regards

Hi @Sliman_Medini, thank you very much for reaching me out. I had already tried console logging, but unfortunately it didn’t log anything.

I can’t attach the .har, so I uploaded it here: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

Thank you so much for your availability.

Best,
Gabriele