References in Smart Fields

Hello everyone,

I’ve got a question about references in smart fields. Is it possible to conditionally specify references to other collections or manage them somehow? I have a field that can be a reference to an entry in one of three possible collections.

Thank you!

const { collection } = require('forest-express-mongoose');
collection('transactions', {
  fields: [
      field: 'playerId',
      type: ['String'],
      // here it can be either player_collection_1, player_collection_2 or player_collection_3
      reference: 'player_collection_1._id'
      get: transaction => {
        const { id } = transaction;
        if (id) {
          return id;
        } else {
          return '--';

Hi @Dmytro,

You basically want to implement a polymorphic Smart Relationship, right?

Hi, @arnaud,

That’s correct!

I am afraid this is not possible so far.

Using Smart Relationships, you’ll have to create 3 distinct Smart Relationships to handle this use case.
I know this not perfect but it should work.

Out of curiosity, why do you have 3 different collections for your players?

Thank you for your advice, @arnaud! I will try that.

As for your question, these are just 3 different entities.