Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SQL DataSource Add Then Fetch

    I have a question on how the SQL DataSource works. We've added some custom DMI to a SQL data source, which all works great. On the "add" operation, we want to also add related records. It looks like the add operation first does the insert, then does a fetch (calling our fetch binding). Is there a way to control when that fetch happens?

    Here's what currently happens:
    1. add operation on data source, inserts to table
    2. fetch code happens immediately afterwards
    3. DMI inserts related records
    4. Response returns
    Is it possible to have step 3 happen first before the fetch executes? Our fetch pulls in data from related records as well, these are missed in the above steps.

    #2
    Just set operationBinding.canSyncCache to false to avoid the automatic refetch, then issue your own fetch (as a separate, new DSRequest) and take the result from that and make it the return data for the original "add" DSResponse.

    Note that setting canSyncCache automatically sets invalidateCache, which you don't want, so reverse that setting when you copy the data over to the original DSResponse.

    Comment


      #3
      I'm trying that, but then I can't get the created primary key from the first insert. Is there a way to retrieve the generated primary key when canSyncCache is false?

      Comment


        #4
        No - there is a morass of database-specific SQL and database bugs in that direction. However, setting canSyncCache is just a minor optimization in this case - you can just allow the default fetch, grab the new PK value, refetch using that and replace the DSResponse data.

        Comment


          #5
          Ok thank you, that makes sense.

          Comment

          Working...
          X