Unable to create a record with a relational object field (many to many)

Options
Jswan
Jswan Member
edited February 2023 in ? Working with APIs

Hey folks! Trying to do what I think is a super simple thing in Xano, but having some difficulty. Thanks for your help in advance.

I have a table POSTS related to another table TECHNOLOGIES via the Object field. I chose object because I don't expect a post to have more than two or three technologies related to it.

All I want to do is create a new post and link the technologies appropriately. I'm in the debugger for the /post (POST) endpoint.

Function stack & variables:

The Input Schema auto-offered by Xano in debugger:

The schema filled out:

The response:

New record is created, but the technology does not save. How it looks in the db:

Now clicking into that cell:

It's most certainly to do with the schema I chose in that technologies array, or somehow I'm not linking the object correctly in metadata.

I tried replacing "technologies_id" with “id” in the Run & Debug technologies array. I tried making the technologies array all full technology objects (i.e. with id, name, etc.). No dice.

What's the standard approach here? Thank you!

Best Answer

  • Jswan
    Jswan Member
    Answer ✓
    Options

    Thanks for the quick reply Ray. I've solved the issue with a combination of your recommendation and changing the structure of the data from a list of objects to a list of integers.

    1. I removed the Database link and manually re-added all of those fields with the same structure:

    2. And, unfortunately, saw the same result (note: technologies_id should be 1):

    3. I then deleted the column for “technologies” in my database

    4. And replaced it with a new column that was an array of integers (instead of an array of objects)

    5. It looks like this:

    6. Successful:

    Appreciate your help! Glad to figure this out.

    Cheers

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    You're not the first person to run into this issue lately. I've been seeing people have success addressing it removing the database-linked inputs, and then re-adding the inputs manually. (Same name, same shape if you like). Let us know if that works, or what results you get next?