Data Management

Create a Table Reference Based on a Different Field

Summary

Hello, Xano Community! Welcome back to our Customer Corner video series. Today, I'll show you how to create a table reference based on a field that is not an ID. This technique is particularly useful when you have a large number of records, and users need to reference a specific record without knowing its exact ID.

The Common Scenario:

Consider a product table where each record is linked to a category through a table reference. Normally, you’d reference this through an integer ID. However, in a real-world application, especially with a vast category table, users on the front end might not know the integer corresponding to each category.

Our Objective:

We aim to simplify this by allowing users to reference categories using a more intuitive field – in our example, the category name, which is text instead of an integer.

How to Set It Up:

Adjusting API Inputs:

  • Initially, our API endpoint accepts a 'category ID' as an integer.
  • Modify this by hiding the 'category ID' input and adding a new input field for 'category name' as text.

Adding and Configuring the Function:

  • Introduce a 'Get Record' database request targeting the 'Category' table.
  • Set the field name to 'category', and the value to whatever is received from the 'category name' input.

Executing the Function:

  • Place this function at the start of your function stack.
  • For demonstration, if we run this function with 'Men's Clothing' as the input for 'category name', it fetches the corresponding record from the 'Category' table, allowing us to access its ID.

Mapping to the Product Table:

  • When adding a new record to the 'Product' table, instead of providing a numerical ID for the category, we utilize the ID fetched through the category name.
  • Implement this by using dot notation to map the ID from the fetched category record to the 'Add Record in Product' function.

Results:

Upon running the modified functions with a text input for the category (e.g., 'Men's Clothing'), a new product is successfully added to the product table, correctly associated with the intended category through its textual name rather than an integer ID.

This approach significantly enhances usability, especially for end-users interacting with the front-end of your application, as they can now refer to categories (or other table references) by name instead of obscure IDs.

Conclusion:

I hope this tutorial helps streamline how you handle table references in Xano, making your applications more intuitive and user-friendly. If you have any questions or need further clarification, please leave a comment below.

Stay tuned for more tips and tricks from our Customer Corner series. Bye for now!

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team’s progress and create a backend that will scale for free.

Start building for free