Autocomplete match only_id, not Reference Field item

I’ve got a model Incomings that has a key fundings like that :

fundings: [{ type: mongoose.Schema.Types.ObjectId, ref: "Fundings" }],

My model Fundings have a specific reference field called “Référence complète” that corresponds to a smart field :

Capture d’écran 2021-03-13 à 19.46.27

Expected behavior

When I want to add elements to my fundings (I renamed it Financements GC in french) array in an Incomings document, I use the add existing fundings and I get the autocomplete input :

Capture d’écran 2021-03-13 à 19.40.47

I should now be able to type and match a “Référence complète” (that is a smart field, you remember ?), but it’s not matching.

Capture d’écran 2021-03-13 à 19.52.05

Actual behavior

Instead, I can only match the _id of the funding. If I type the _id, I get the match, it’s not working when I type a “Référence complète” item.

Capture d’écran 2021-03-13 à 19.51.52

Hello @XavierColombel,

In this particular case when referencing a smart field, you will also have to implement the search method.

You can find the documentation about how to search, sort and filter on smart fields here :slight_smile:

Here is an example:

const { collection } = require('forest-express-mongoose');
const models = require('../models/');
const _ = require('lodash');

collection('customers', {
  fields: [{
    field: 'fullname',
    type: 'String',
    get: (customer) => {
      return customer.firstname + ' ' + customer.lastname;
    },
    search(search) {
      let names = search.split(' ');
    ​
      return {
        firstname: names[0],
        lastname: names[1]
      };
    }
  }]
});