Data Management

Create a table reference based on a field that is not the ID

Summary

Hey there! In this guide, we'll explore how Xano can help you handle backend logic without writing a single line of code. We'll use a simple example to demonstrate how you can create relationships between tables based on user input from your front-end application. Let's dive in!

Setting the Stage

Imagine you have an "Organization" table in your database, and you want to add a new record to it. The table has fields for the organization's name and a reference to the category it belongs to. However, instead of asking the user to input the category ID (which can be confusing for non-technical users), you want them to provide the category name, and Xano will handle the relationship automatically.

Step-by-Step Guide

Follow these steps to achieve this functionality:

  1. Hide the Category ID Field: Since you don't want the user to input the category ID directly, you can hide this field from your front-end form.
  2. Add a Category Name Input: Add a new input field to your front-end form where users can enter the category name.
  3. Navigate to the Function Stack: In Xano, head over to the "Function Stack" section, which is where you'll define the backend logic.
  4. Get the Category Record: Under the "Database Requests" section, create a new function to get the category record based on the user-provided category name. Set the "Field Name" to the column name that stores the category name (e.g., "type"), and map the "Value" to your category name input field.
  5. Retrieve the Category ID: The response from the previous function will contain the actual ID of the category record. You can access this value using the variable name assigned to the response (e.g., `category_one.id`).
  6. Add a New Record: In the "Add Record" function, use the category ID retrieved in the previous step to create the table reference for the new organization record. You can do this by using dot notation on the response variable (e.g., `category_one.id`).
  7. Test and Deploy: With everything set up, you can test your logic by providing a category name and running the function stack. If successful, you should see the new organization record added to the database with the correct category reference.

And that's it! By leveraging Xano's visual interface and function stack, you can easily handle backend logic without writing a single line of code. This approach not only simplifies the development process but also makes it more accessible to non-technical users and developers alike.

Benefits for Different Audiences

  • No-code enthusiasts: Build and launch applications quickly without relying on developers, enabling you to bring your ideas to life faster.
  • Citizen developers: Create internal tools, automate workflows, or build department-specific applications without extensive coding knowledge.
  • Traditional developers: Prototype ideas rapidly, offload backend development tasks, and focus more on frontend and business logic.
  • Startups and small businesses: Build and deploy applications cost-effectively with limited resources or technical expertise.

Xano empowers you to streamline your backend development process, making it more efficient and accessible. Give it a try and see how it can revolutionize your application development workflow!

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