You are not logged in.
Pages: 1
Hi!
I need to implement addition (new parameter for TSQLRest.Add method) to ignore selected columns during adding/inserting new record (I have DB-First approach for existing project where mORMot is introduced). I need to let DB to fill few of my columns (and that can't be changed).
Is any sense to preparing patch for this (because it will be ignored)? I'd also like to fix "Insert new record and Bad Request (400)" ( http://synopse.info/forum/viewtopic.php?id=3245 ).
best regards,
Maciej Izak
Offline
that was fine for beginning of including mORMot in my big project (~600 tables and 6 MLOC) for some tables but the fields are used in many tables for update, select etc. So I need to put these fields in the TSQLRecord definition. The insert is the only case in DB-First approach when I need to omit some fields. I'd like to omit declaring two models for each table...
The new parameter for "Add" seems most logically. I don't see any alternative.
best regards,
Maciej Izak
Offline
What you can try is change TYourTable.RecordProps.SimpleFieldsBits[soInsert] to exclude the bits of the non needed fields.
Please also try http://synopse.info/fossil/info/6fffa2ab16
which renamed TSQLRestStorageExternal.EngineAddIgnoreID boolean as a "EngineAddForcedID: TID" property.
Put here a "fake" ID which would be returned when TSQLRest.Add() is called, as a non 0 "fake" ID - it should avoid the 404 error.
Offline
Thanks ab, nice smart solution, but it is missing additional check for decode fields in TSQLRestStorageExternal.ExecuteFromJSON:
should be
// decode fields
if fEngineAddForcedID = 0 then
Decoder.Decode(SentData,nil,pNonQuoted,InsertedID,true) else
Decoder.Decode(SentData,nil,pNonQuoted,0,true);
instead of
// decode fields
Decoder.Decode(SentData,nil,pNonQuoted,InsertedID,true);
without modification is raised exception: TSQLRestStorageExternal.JSONDecodedPrepareToSQL(TSQLxxx): No column for "ID" field in table public.xxx
btw. I am working on ignoring columns
best regards,
Maciej Izak
Offline
Please try http://synopse.info/fossil/info/3fd36c702d
Offline
thanks, works as expected.
Patch is ready. To be consistent with standard SQL and with other mORMot parts, I must to say that "excluding" is bad idea. Instead of excluding is used standard approach with CustomFields. All old code will work as before (with small exception for one virtual Add, but IMO this is the must to keep clear code base):
https://drive.google.com/file/d/0B4PZhd … sp=sharing
example usage:
function NewMaleBaby(Client: TSQLRest; const Name,Address: RawUTF8): TID;
var Baby: TSQLBaby; // store a record
begin
Baby := TSQLBaby.Create;
try
Baby.Name := Name;
Baby.Address := Address;
Baby.BirthDate := Date;
Baby.Sex := sMale;
result := Client.Add(Baby,true,'Name,Address,Sex'); // (!!!) BirthDate is filled by DB
// also is possible to call:
// result := Client.Add(Baby,true,'*');
// which is equal to:
// result := Client.Add(Baby,true);
finally
Baby.Free;
end;
end;
best regards,
Maciej Izak
Offline
I need to know whether the patch will be included. This is the key feature for my team, so eventually I need keep this somehow outside the core of mORMot library.
best regards,
Maciej Izak
Offline
Please check http://synopse.info/fossil/info/ef66456cb4
Offline
Horray! mORMot is now very tasty in including to existing project!
As far as I understand "SendData" parameter is useless for our case?
best regards,
Maciej Izak
Offline
Pages: 1