How To Add Records After Querying

Options

Hi, I'm working on an app that needs to show a list of objects (5 meditations) for each week. I query the 5 based on their timestamp which works perfectly. This 5 will change every week and I want to update a table that holds the current list. (Im doing this because simply querying them returns nothing on the weekends)

I have a function stack that will run once a week and update the meditations by deleting what is there, querying the new records for the current week, and adding the new records. I have the delete and the query working, but I cant figure out how to add the new records.

The bulk add is useless the way I understand it because it doesnt allow me to map fields. So I'm looking at adding them 1 by 1. It's only 5 so it shouldn't be too bad.

When I'm adding a new record, how can I reference the id of the first object in the variable that contains the queried objects? and the second, and the third etc. I understand dot notation but I'm not sure how to reference specific objects in an array.

Answers

  • arturosanz
    arturosanz Member ✭✭
    edited September 2023
    Options

    You have two options to access an object property from a list of objects.

    A) The brute force way. It could be acceptable in your case because you have only 5 records to add.

    meditation_1.0.id

    meditation_1.1.id

    meditation_1.2.id

    meditation_1.3.id

    meditation_1.4.id

    This is brute force because you have to hard code them as is, and you can't use the sprintf filter to iterate in a loop. Basically, doing meditation_1.%d.id sprintf index won't work.

    B) The elegant way.

    Use the get filter on an array to access its items by their index. Use the For Loop function to get access to the index variable and run it for array count times. Then access the id property like so: meditation_1 get index get id.