Creating Rows If Not Created Already

Options
NWold
NWold Member

I want to use POST to create a row using a users_id and a clubs_id. I want it to be that a user can't have multiple rows with the same club. How do I go about creating a function stack for such:

Tagged:

Answers

  • Lachlan
    Lachlan Administrator

    ADMIN

    edited October 2023
    Options

    Hey there,

    It sounds like you might first want to do a query all records step to your UserClubInteractions table with a custom query:

    Where Club ID (DB) = Club ID (Input)
    And where User_id (DB) = user_id(input)

    You can set the output of the query all records step to Exists which will return a true or false if a record exists.

    You can then use a pre-condition or conditional with a query where if the output of your query all records step = True. If true then, add the record.

    Let me know if this works!

  • arturosanz
    arturosanz Member ✭✭
    Options

    @NWold Another option to prevent having two records with the same combination of user_id and club_id is to create a table UNIQUE index with those two fields. Xano won't let you create more than one record with the same combination of user_id and club_id.