Custom integration: Define Lookup fields

I have a custom integration with multiple databases. I have relations working correctly according to the documentation.

After databases, fields and relations are created, I have created a few simple Lookup fields to access more information.

Is it possible to define lookup fields in code? If so, where can I read more about it (I did not manage to find anything about lookup in the documentation)?

Why do you want/need to use code to create the relation field?

I’ve had some problems with databases getting corrupt and have been forced to start from over again. And I’ve had to define the Lookup field again.

Having stuff defined in code feels better and I won’t forget the extra manual steps later :slight_smile:

But let’s also say that I would like to have this custom integration as something to be shared with other people later on. It would be nice if the Lookup field is defined from the start (with code) and not something each individual user would have to setup.

Does that make sense? Or do you see another way of achieving the same thing?

I’m just curious if Lookup-relations can be defined in code since it can be defined in Fibery manually.

1 Like

A lookup fields is basically the same as a formula field. Here is what one of my lookup fields looks like when I query the schema:

 {
    name: 'Demo/Lookup',
    id: '6fa1fb3f-bd70-49fe-b904-f4136f98f2b8',
    type: 'Demo/Database',
    rawMeta: {
      'ui/object-editor-order': 2,
      'formula/lookup?': true,
      'fibery/collection?': true,
      'fibery/field-reversed-collection?': true,
      'fibery/readonly?': true,
      'formula/formula?': true,
      'formula/formula': {
        expression: {
          'q/from': [ '667ed2d8-594f-42ab-8f18-1594b03dbf99' ],
          'q/select': {
            'fibery/id': {
              'q/from': [ 'eeec31e0-b1e9-482a-a422-b2fe888547ca' ],
              'q/select': {
                'fibery/id': [ '386c69d2-f00e-4241-9dc9-8dd1167664a5' ]
              },
              'q/limit': 'q/no-limit'
            }
          },
          'q/limit': 'q/no-limit'
        },
        params: {}
      },
      'history/disabled?': false
    },
    holderType: 'Demo/Task',
    isCollection: true,
    isTitle: false,
    isId: false,
    isPublicId: false,
    isReadOnly: true,
    isFormula: true,
    isFormulaDisabled: false,
    formulaDisableReason: null,
    formula: {
      expression: {
        'q/from': [ '667ed2d8-594f-42ab-8f18-1594b03dbf99' ],
        'q/select': {
          'fibery/id': {
            'q/from': [ 'eeec31e0-b1e9-482a-a422-b2fe888547ca' ],
            'q/select': { 'fibery/id': [ '386c69d2-f00e-4241-9dc9-8dd1167664a5' ] },
            'q/limit': 'q/no-limit'
          }
        },
        'q/limit': 'q/no-limit'
      },
      params: {}
    },
    isLookup: true,
    hasLinkRule: false,
    linkRule: null,
    relation: null,
    defaultValue: null,
    objectEditorOrder: 2,
    isRequired: false,
    isHidden: false,
    isDeleted: false,
    disableLinkExistingItems: false,
    version: 1438,
    typeObject: [Getter],
    mixinTypeObject: [Getter],
    holderTypeObject: [Getter],
    nameParts: [Getter],
    title: [Getter]
  }

You could potentially create a lookup field, using API calls and a bit of ‘reverse engineering thinking’ (we don’t have documentation, since it’s not really something we want to support).

However, the formula definition utilises the ids of existing fields/relations, so in your case, it is likely to be very challenging, since you would need to query the schema to find the correct ids, after the integration is created.

I might suggest as an alternative, that you create a relation field in your custom integration, and fill in the values based on a query that runs in the integration code.
i.e. if you have these dbs: Project → Feature → Task and you want to lookup the Features’ Tasks in the Project db, just create a relation between Project and Task, and write the code in the integration to populate this with the correct values.

2 Likes

Thanks, I’ll do that.