Adding specific data to record only once when 1st object in list is created 🧐

Fredk Member ✭
{"type": "preface", "body": "some paragraph"},
{"type": "chapter_1", "body": "some paragraph2"},
{"type": "chapter_2", "body": "some paragraph3"},
{"type": "chapter_3", "body": "some paragraph3"}

My function stack adds one record (1 object at a time), then queries all records. But I need to add the preface content only once, when a new book is created. Anyone knows how to do this, maybe with a "conditional" variable?


  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭

    Seems like you need to query records beforehand to check if preface one is already there. If you are having a loop for adding the objects then you most likely want to check it outside of itso you are not making the query during every iteration.

    You can query with exists type that return a true or false depending on the existence of a particular records. Based on that you can create a conditional to add the first object with preface if the query is false.

    Hope that helps