Smart Relationships Not working

We have complex relationships between the two collections, i.e., “Companies” & “Consumers.”

Companies schema

{
    ...
    'applicationId': String,
    'users': [{ type: Mongoose.Schema.Types.ObjectId, ref: 'consumers'}],
  }

Consumer schema

{
    ...
    'applicationId': String,
  }

By just this much, I was not able to create the relationship then. I tried another method by adding this code to forest “companies” fields,

{
      field: 'users',
      type: [Object],
      ref: 'consumers',
      reference: 'consumers.applicationId',
    }

Still, this didn’t solve then. I manually added the route for the APIs that forest was calling when getting all consumers for an application. Still, by doing this, when I navigated to consumers’ tabs, initially, all fields were empty.

Hello @skdev24,

Can you please share with us the required info when creating a new community post?

  • Project name: …
  • Team name: …
  • Environment name: …
  • Agent type & version: …
  • Recent changes made on your end if any: …

This will give us context about your project, and help us identify the issue.

As it seems that you’re not referencing the document id from companies, I suggest you to create a smart relationship as explained here in the docs.

This way you’ll be able to make it work properly.

Hey @GuillaumeGautreau,

Thanks for the advice routes/product.js file did help in connecting two collections with different reference keys.