Issue with update request : Table reference field

Options

Hello to all !

I'm a little bit stuck with endpoints that I use to update records, I use the function first_notempty on my fields (not to overwrite the values of my table if the fields are null or empty during the update) it works well on my fields of type text but I have a problem on my fields of type table reference :

  • it overwrites me anyway, since it is an array of id there may be a step more to do but I do not see what... I don't know what to do.

Anyone has an idea on how to solve that ?

ps: I think I should use a function that I could reuse in all my maj endpoints because going through all the fields one by one is a bit long...

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @Mamad you are right, arrays and objects are a bit different than scalar data types and often require a little extra work. Adding to an existing array you will want to use the Merge function or Merge filter with the existing array and new array.

    But if you are just adding a single value that is not an array to the existing array then I recommend the Push filter to push the value to the array.

  • Mamad
    Mamad Member
    Options

    Hi @Michael Udinski , thank you for your answer , so for arrays I don’t need to use the first_notempty filter?

    Let me see if I have understood the merge : if I have an array [1,2,3] and a second [1,5,6] the result will be [1,2,3,5,6] ?


    by the way , as I have a lot of table ( also a lot of endpoint for update ) , do you think it’s possible to create a reusable function with a json as an input and a function stack to update each field in a record present in the json input ?

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    so for arrays I don’t need to use the first_notempty filter?

    You can still use first_notempty for arrays.

    Let me see if I have understood the merge : if I have an array [1,2,3] and a second [1,5,6] the result will be [1,2,3,5,6] ?

    In this scenario, your new array would be [1,2,3,1,5,6]. You could apply the unique filter if you want unique values.

    do you think it’s possible to create a reusable function with a json as an input and a function stack to update each field in a record present in the json input ?

    Yes, you could definitely create a custom function to re-use the logic throughout your workspace.

  • Mamad
    Mamad Member
    Options