Having difficulty saving array of integers as table reference list

Options

Hey folks! Thanks in advance for reading. I'm sending an array of integers from custom frontend (React Native) to Xano backend, and saving as a table reference list.

One POST has many TECHNOLOGIES.

It all works correctly in debugger:

But it does not work correctly in practice:

Xano appears to be expecting a single integer.

To make matters weird, when there's just one integer in the technologies_id array sent from frontend, then it works as intended:

Any ideas? Just want to save an object that refers to another table as expected 😭

Thanks!

Tagged:

Best Answer

  • MattLaro
    MattLaro Member ✭✭
    edited March 2023 Answer ✓
    Options

    [… removed comment regarding array foreing key since not relevant to topic. … ]

    Did you try perhaps getting a json value input and passing a "safe_array" filter on it ?

    Here's the different results :

    Of course, this would require you to validate that numbers have been passed though, but perhaps the extra step could help you get through the array as a string barrier :)

Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @Jswan this looks like to be a simple case of data types. You'll see the difference when the values are blue this signifies that it is actually an integer. But the white signifies that it is text.

    For example, here you are getting a list of integers:

    But here you are getting the text string “[5, 6]”

    This is not a list of text with values 5 and 6… it is a text string altogether with the flat brackets.

    I'd recommend changing the way these values are passed on your front-end so that they match the expected input of an array of integers (table references).

  • Jswan
    Jswan Member
    edited March 2023
    Options

    Yep totally! I see the type error.

    I guess the “to make matters weirder” section is really the crux of my confusion -

    1. I'm sending an array of integers from the frontend that I package in a sendable format by using JSON.stringify().
    2. If the array of integers from the frontend is length 1 (i.e. there's just one integer value), then Xano accepts the code correctly.
    3. If the array of integers from the frontend is length >1, then Xano does not parse through and save the integers as expected. It perceives the JSON as a string and goes no further. That feels like a bug but I'm new to all this, so definitely not to be trusted :)

    Thanks for the response. I'll focus on figuring out how to package the data correctly on the frontend. You must be right.

    But just in case this is a Xano bug or I'm not understanding how to correctly accept & create an Object in Xano - for anyone who's used Object fields and received an array of integers, is there any manual processing in Xano that's required within the Function Stack (i.e. a function for deserializing values), or should the JSON for an array automatically create an Object?

    Cheers & thanks again!

  • Wes Wagner
    Wes Wagner Member
    Options

    @Jswan I'm running into the same issue. I also have an endpoint that should accept an array of integers (that is also a file input), and I'm unable to solve this bug. I plan to reach out to Xano support.

  • Jswan
    Jswan Member
    Options

    Let me know how it goes @Wes Wagner ! For now, I'm just using classic SQL-style join tables, but would be great to use their nifty-looking objects-as-fields structure

  • Wes Wagner
    Wes Wagner Member
    edited March 2023
    Options

    @MattLaro amazing suggestion. That worked like a charm. Thank you!

    For the record, I still feel like this is a Xano bug, but I'm happy to continue with what you suggested.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @Wes Wagner the API wouldn't be changing the input structure. Just how the data is inputted from the front-end in this case. @MattLaro's solution is a great one and shows the power of Xano being able to transform data the exact way you need it

  • Jswan
    Jswan Member
    Options

    Beautiful! Thanks all @MattLaro @Michael Udinski @Wes Wagner - off and running 🏃‍♂️