Data Store - Upsert - Wich Record

About the Data Store, the UPSERT action.
I believe that “Wich Records” search the Data Store following the values I set, find this record, and update, if not found, insert one record, right?

This search is made using “AND” or “OR”? For example, using the fields of the image below, this component search for records where home_id = 1 AND inclusion_field_id = 2? OR home_id = 1 OR inclusion_field_id = 2?

Another question, I’m using dmx.parse from a javascript file to run the “upsert”:

I want update this Data Store:

`

Using this upsert:

dmx.parse("content.conditional4.ds_inclusion.upsert({ home_id:112, inclusion_field_id:152, job_id: 182, location_id: '0' }, { attr_value: 'Matching external finish,Other'})")

But this is the result of the above statement:

See that I want to update the record with:

home_id:112 
inclusion_field_id:152
job_id: 182
location_id: '0'

But upsert is updating other records! If the operator with “Which Record” is “OR”, it is explained…
Help! :fearful:

I created a button in my page and simulate the same action using “on click” and “upsert” is updating all the lines, not respecting the “wich records”!

Is this a upsert with data storage bug @Teodor, @patrick? Or am I using it in a wrong way?

Does it do this only with the upsert or also with the update?

both! with delete as well!

I’ve only ever been able to get this working with one field (usually an ID) rather than a combination of two using AND or OR

It would be really useful for this to be an option, though. I guess it will likely be AND (where all criteria are met) but maybe the genius that is @patrick can find a sensible way to give AND/OR options - something like the query builder conditions would be incredible!

@bpj I remember use upsert with multiple condition in an array and it worked fine!

I don’t think I ever used an array like that - I tend to use a datastore these days :man_shrugging:

1 Like

yes, it was before the data storage era LOL

1 Like

I had to check the code to see if it does OR or AND on the Which Records. Is seems that it is doing OR. Strange that it didn’t update all your records, since they all have home_id: 112.

@patrick, thanks. So the operator seems to be “OR” ! The other fields are different!
When I run the upsert from a button inside the page, it updates all the registers.

When I run inside of javascript file, it is a different flow (my first post).

Hello @patrick! Is possible to use “AND” instead of “OR”? Thanks!

That’s not currently possible.

1 Like

:dizzy_face:

Create a Feature Request - I’d vote!

1 Like

I haven’t used the Upsert with multiple criteria like this either, but if I did, I would usually want and expect it to use AND not OR. (It would seem more like a bug than a feature to use OR).

I’d vote too.

1 Like

Featured request created!

Yes, you can use AND! :rocket:

You just need need to know the magic trick…

If you have field1 with value f1 and field2 with value f2, create a field1_field2 with value f1_f2 and test for that…

I do it in many places in my app and it always works perfectly!

2 Likes

Cool @Antony! Thanks!

1 Like