Transaction Operations Chaining — using result in queries inside the transaction?

Tricky question which perhaps has the answer “that’s not possible”:

Say you have a transaction with the 1st operation being a “find” operation. Then you want to run a second operation which is also a “find”, but you want to use part of the result of the 1st operation (e.g. “objectId” in the 1st item of that result) in the WHERE CLAUSE of the second operation… is this possible?

Our specific use case: user logs in and we want to run a transaction where we find an object they own in one table… and then we want to find all the objects in another table which are related to that first object… so we can get various things our app needs for the user to navigate around in a single transaction on log in. Any help much appreciated :grinning:

What you describe is possible. For transaction operations chaining, I recommend starting here:

With your specific use-case, I think it should be possible to do with one query though.

Yeah, I watched that video… and asked the same question on YouTube :grinning:

Right now, have a workaround (using email of current user in all queries in the operations, sometimes with a chain of “xxxxx.yyyyyy.email” in the query. Seems to work well :+1:

Do you need a sample showing it in the chaining or help with a single query that fetches the data?

Kind of related, and also related to “optimize to cut down on API calls” in light of the Scale Plan pricing… when getting the result of an operation in a transaction (after the transaction completes) like so:

Is that an API call or is that just getting data from the users browser, as found in “Preview” in “Network”?

An example would be awesome (where operation 2 is a “find” with a query that contains part of the result of the previous operation) :grin:

Hello @Alex_Klein

Get Transaction Result do not make a call to the server. Here is an example

Now when I call the method I got:

1 Like

@mark-piller Please post a simple example of chaining two find queries together. What I have isn’t working -

EDIT - To clarify, my first query returns results. The second doesn’t.

Thanks,
Tim

Do I understand correctly that the chaining you would like to implement should work like this?:

  1. Run query A
  2. Get the objectId property from the first object from the result of query A
  3. Use (2) in the second query

@mark-piller Exactly!

Hi Tim,

I looked into it and I believe it is not possible for the following reason:

At the time when the where clause is composed for the second query, the result from the first one is not available. The where clause cannot include a reference to a result, it should be a complete scalar value by the time the entire sequence of operations is sent to the server in the transaction. Here’s a visual representation of what I mean:

I apologize for not catching it earlier at the beginning of this thread.

The following graphic from our docs actually shows that none of the errors come into the “Retrieving Objects” block, this means the data retrieval operation cannot use a result of another operation:

Regards,
Mark

Thanks for looking into this for me, @mark-piller.

Best,
Tim