I have a bunch of Tables in DA Schema that are in a master-detail relation. One example is customer table and activity table, customer being the master table. My primary key in the Customer table is a string. What i want to do is something similar to what dataabstract does with the generator and the AutoInc fields, meaning that in the update process it also changes the keys in the detail table so it matches the new master key. Can something like this be achieved?
Am I right that you need to implement the following scenario:
Client-sde some rows are inserted into the master and detail tables, with master key field set to some placeholder value
Update is sent to the server
Server-side a proper master key value is generated based on some rules and then both master and detail rows are inserted with this proper master key value.
Client retrieves information about hte real master key value and updates both detail and master rows
The client is a javascript application and the server is written with delphi.
The scenario is right till point 3. I use a placeholder as the key. As i mentioned i try to achieve something similar to the AutoInc field and Generator. I also have tables with Integers as primary key and the key’s are changed in both master and server, but in this particular case i need to use a string as a key.
Tried with a custom insert command in the schema but that inserts the master rows with the new key but my detail rows have the old placeholder.
Isn’t there any method to extend the system that works for AutoInc to work for strings as well. I already thought about a possible solution, meaning that i have to manually change the detail keys in the BeforeProcessDelta event but that means that i have to implement the changes for all my tables while if i extend the system that works for AutoInc the framework will handle it as a natural behavior
you store all deltas into local variable in DAService.OnBeforeProcessDeltas event
in DAService.BusinessProcessorAutoCreated you assign to newly created BusinessProcessor, OnBeforeProcessChange event
in above event (OnBeforeProcessChange) you should detect if change belongs to details table and you can change master key.
Note: in 3rd step you should use TDADeltaStructList that is stored in 1st step and ServiceSchema.RelationShips that should store foreign keys. foreign key gives you information about master table for given table and fields in master key