#1 2021-05-17 15:50:52

keinn
Member
Registered: 2014-10-20
Posts: 103

AS_UNIQUE and woStoreStoredFalse design problem

AS_UNIQUE can mark a field value to be unique in the table,
but the woStoreStoredFalse option can not be set with
_ObjFast(const NameValuePairs: array of const)  overload function,
therefor ,the filed marked as_unique won't be serialized ,it just missing.

i know i can use  _ObjFast(aObject: TObject;  aOptions: TTextWriterWriteObjectOptions = [woDontStoreDefault]) overload function,

but there are so mary scenarios  _ObjFast(const NameValuePairs: array of const) comes more handy.

throuth the code ,woStoreStoredFalse is to protect some sensitive information like password,
the AS_UNIQUE should mean "unique", not "sensitive"
may be we need another marker to do so.

Offline

#2 2021-05-17 16:02:33

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: AS_UNIQUE and woStoreStoredFalse design problem

and with this AS_UNIQUE , when use the ctxt.Returns(const NameValuePairs: array of const;....) to return some Torm data, those filed are all missing

Offline

#3 2021-05-18 10:31:35

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: AS_UNIQUE and woStoreStoredFalse design problem

AS_UNIQUE is just a trick for better readability of ORM-specific property definition.

In regular class definitions, just use "stored false" as with regular pascal code.

Offline

#4 2021-05-18 21:09:46

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: AS_UNIQUE and woStoreStoredFalse design problem

I am suffering a similar/related issue (mORMot2).

To use ObjectTOJSON, I have to explicitly specify ObjectToJSON(myObject, [woStoreStoredFalse]), otherwise, the object won't be correctly serialized (i.e., those AS_UNIQUE fields will be missing).

Last edited by wxinix (2021-05-18 21:18:21)

Offline

#5 2021-05-19 08:54:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: AS_UNIQUE and woStoreStoredFalse design problem

Now I understand your problem.

If you use TOrm, "stored AS_UNIQUE" is interpreted as "stored false" by ObjectToJson() so some fields are missing in the JSON.
This is indeed a bug.

I have introduced rcfDisableStored RTTI option so that  TOrm "stored AS_UNIQUE" attributes are ignored during JSON serialization.
It should fix your issue.

Offline

Board footer

Powered by FluxBB