Displaying name instead of ID for relation

Let's review the case when you need to display a value in the table instead of a foreign key field from a related table. For example, you have Users and Orders tables that both have the User id field. So instead of displaying just the user id, you can display the user name value for convenience.

Here's how you can do that๐Ÿ‘‡

  1. Select the Orders table and click on the User id column to open its settings.

  2. Change the default type of the field (Number) to Select/Tag in the Type dropdown.

  3. Now, in the Options field below, switch to the JS mode, and specify the following code:

return {{actions.loadUsers.data}}
  .map(user => {
    return { 
      value: user.id,
      title: user.first_name
    }
  });

This code maps the first name value from the Users table to the user id value from the Orders table.

That's it! Now, you'll see users names displayed instead of their ids.

Last updated

Was this helpful?