Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: FireDAC and REST Master-Detail update issue



Permlink Replies: 2 - Last Post: Nov 29, 2017 2:18 AM Last Post By: Christophe Ravaut Threads: [ Previous | Next ]
Arkady Semylio

Posts: 87
Registered: 9/18/15
FireDAC and REST Master-Detail update issue
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 25, 2016 6:56 AM
Sorry if the question can seems stupid or the argument was treated before,
however I've a weird problem with a implementation test.

I'm trying to move a master-detail from a classic rdbms conection to a rest/json
datasnap architecture using firedac. Now, I'm not using livebindings as I've already
a lot of code written in a "classic" style, i.e. TDBGrids, TDBNavigators connected
with TDataSources to TDataSets derived components... and so on... so I don't
want to convert my legacy code to the new livebindings paradigm.

Regarding fetch, insert and delete records, as well as editing them, on the "master"
dataset on server side, I haven't absolutely problems. But when I went to modify
records on the "detail" dataset, again on server side, I'm faced to the problem of updates
on multiple rows when only one was required. It seems a problem related to the
fact the foreign key value was ignored. So all records having a specified value
were updated regardless from the foreign key.

void TServerMethods1::ApplyChangesDetail( TJSONObject* AJSONObject )
{
    String const sDetail = _T( "Detail" );
 
    TFDJSONDeltas *LDeltas = new TFDJSONDeltas();
    TFDJSONInterceptor::JSONObjectToDataSets( AJSONObject, LDeltas );
 
    unique_ptr<TFDJSONErrors> errs( new TFDJSONErrors() );
 
    // this line generate the error regardin multiple updates
    TFDJSONDeltasApplyUpdates::ListApplyUpdates(  
        LDeltas, sDetail, FDQueryDetail->Command, errs.get()
    );
 
    if ( errs->Count > 0 ) {
        throw Exception( errs->Strings->Text );
    }
}


Now, how can I furnish the FK value to ListApplyUpdates in orde to apply
it in the update operation?

The query on the detail data set has a parameters (the FK), :IdMaster

SELECT 
   [Value1]
  ,[Value2]
FROM [tblDetail]
WHERE [IdMaster] = :IdMaster


I'm new to FireDAC REST techs, and I can't figure out how to escape
from this problem. I've also tried to fill events like OnBeforePost on detail
dataset on server side in order to supply the value by means of Parameters
container, but I can't even see that event called.

Thanks in advance.

Bye bye

Any clues?
Arkady Semylio

Posts: 87
Registered: 9/18/15
Re: FireDAC and REST Master-Detail update issue
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 25, 2016 7:19 AM   in response to: Arkady Semylio in response to: Arkady Semylio
ok, solved adding the FK to the list of columns just after the select keyword.

Arkady Semylio wrote:
SELECT 
   [IdMaster]
  ,[Value1]
  ,[Value2]
FROM [tblDetail]
WHERE [IdMaster] = :IdMaster

But, since the value is the same for the entire recordset, it seems to me a waste
of bandwidth to send such repeated coherent value via JSON. The client already
knows the value because sent that value to compose the request.

I cant understand as the TFDJSONDeltasApplyUpdates::ListApplyUpdates works
in detail, as the documentation for this class is poor in XE8 and I haven't time to study
the sources.

Bye bye
Christophe Ravaut

Posts: 1
Registered: 10/26/02
Re: FireDAC and REST Master-Detail update issue
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 29, 2017 2:18 AM   in response to: Arkady Semylio in response to: Arkady Semylio
Hello Arkady Semylio,

Do you also have an insert of the master/detail?
If Yes, did it works with the ListApplyUpdates or must you use another approche?

Regards,
Christophe
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02