You are not logged in.
Hi, I have a problem with the procedure:
http://127.0.0.1:888/service/User/1/Orders, my class is as follows:
TSQLFile = class(TSQLRecordSigned)
private
fOwner: RawUTF8;
fCheck: Boolean;
fIsSystem: Boolean;
fAssociatedRecord: TRecordReference;
fAssociatedID: Integer;
function GetDisplayName: RawUTF8; virtual;
public
fName: RawUTF8;
fModified: TTimeLog;
fCreated: TTimeLog;
fPicture: TSQLRawBlob;
fKeyWords: RawUTF8;
fLabel: RawUTF8;
fImageIndex: Integer;
fEnabled: Boolean;
function CheckValues(reference: TSQLRecord): Boolean; virtual;
procedure CopyFrom(ARec: TSQLRecord); // : TSQLRecord;
procedure CopyTo(var ARec: TSQLRecord);
property DisplayName: RawUTF8 read GetDisplayName;
property Check: Boolean read fCheck write fCheck;
published
property Name: RawUTF8 read fName write fName;
property Created: TTimeLog read fCreated write fCreated;
property Modified: TTimeLog read fModified write fModified;
property Picture: TSQLRawBlob read fPicture write fPicture;
property KeyWords: RawUTF8 read fKeyWords write fKeyWords;
property SignatureTime;
property Signature;
property Enabled: Boolean read fEnabled write fEnabled;
property Label_: RawUTF8 read fLabel write fLabel;
property ImageIndex: Integer read fImageIndex write fImageIndex;
property Owner: RawUTF8 read fOwner write fOwner;
property IsSystem: Boolean read fIsSystem write fIsSystem;
property AssociatedID:Integer read fAssociatedID write fAssociatedID;
property AssociatedRecord:TRecordReference read fAssociatedRecord write fAssociatedRecord;
end;
TSQLUserOrders = class(TSQLRecordMany)
private
fSource: TSQLUser;
fDest: TSQLOrder;
published
property Source: TSQLUser read fSource;
property Dest: TSQLOrder read fDest;
end;
TSQLUser = class(TSQLFile)
private
fOrders: TSQLUserOrders;
published
property Orders: TSQLUserOrders read fOrders;
end;
TSQLOrder = class(TSQLFile)
private
fOwner: RawUTF8;
....
published
property Users: TSQLUserOrders read fUsers;
end;
I copy this from document "synopse mORMot Framework SAD 1.18 pdf" :page 228,229
....
For instance, you can see the below unique URI format for customer and orders fetched:
Customer data
URI
Get orders placed by customer "smith"
http://www.mysite.com/Customer/smith/Orders
Here, "dupont" and "smith" are used as unique identifiers to specify a customer. In practice, a name is far from unique, therefor most systems use an unique ID (like an integer, a hexadecimal number or a GUID).
...........................
When I create the server must also register the method TSQLUser.Orders
I have also seen this question but I did not understand what I write:
http://synopse.info/forum/viewtopic.php?id=926
if I execute "http://127.0.0.1:888/service/User/1/Orders" from browser error occurs 400, and it returns only the user 1 and not his orders!!
Thank Corchi
Last edited by corchi72 (2015-11-19 16:21:11)
Offline
The http://www.mysite.com/Customer/smith/Orders was a theoritical sample for a pure REST implementation.
This is not how mORMot routing works.
"http://127.0.0.1:888/service/User/1" would return the whole record.
But "http://127.0.0.1:888/service/User/1/orders" won't make the JOIN for you.
A sub-folder would only work for BLOB fields, not one-to-many fields.
Offline
Excuse me,
but then I do not understand what gives the heading methodname.
I ask this because I had also implemented a method published in the class TSQLUser that read the orders for user, but is not found in the list of public methods!!!
see this :
procedure TSQLRestServerURIContext.URIDecodeSOAByMethod;
begin
if Table=nil then
// check URI as 'ModelRoot/MethodName'
MethodIndex := Server.fPublishedMethods.FindHashed(URI) else
if URIBlobFieldName<>'' then
// check URI as 'ModelRoot/TableName[/TableID]/MethodName'
MethodIndex := Server.fPublishedMethods.FindHashed(URIBlobFieldName) else
MethodIndex := -1;
end;
I have to write this method in TSQLRestserverDB or just write in the class method:
TFileServer = class(TSQLRestserverDB)
private
public
function LoadOrders(Ctxt: TSQLRestServerURIContext): string;
end;
or
TSQLUser = class(TSQLFile)
private
fOrders: TSQLUserOrders;
public
function LoadOrders(Ctxt: TSQLRestServerURIContext): string;
published
property Orders: TSQLUserOrders read fOrders;
end;
function TSQLUSer.LoadOrdes(Ctxt: TSQLRestServerURIContext): string;
var
content: RawUTF8;
begin
content := fOrders.FillContext.ToString;
Ctxt.Returns(content, HTML_SUCCESS, HEADER_CONTENT_TYPE + JSON_CONTENT_TYPE);
end;
Offline
1. The method should be defined in the "published" section of the SERVER class.
2. If this is not the server class, it should be added to the server via ServiceMethodRegisterPublishedMethods or ServiceMethodRegister.
Offline
so, I can not call a public method of a class type TSQLRecord...
ok thanks corchi
Offline