You are not logged in.
Pages: 1
I'm testing mormot2 with FPC Win and Linux and convert 30-MVC Server sample to PUREMORMOT2
You can download converted sample from http://halkyon.com/download/MVCServer.zip
In MVCViewModel.pas
1. Default URI is OK
2. AuthorView is broken with "out Author: TOrmAuthor" parameter, I changed to "var Author: TOrmAuthor" and now is OK (line 42)
3. ArticleView is broken, exception on TObjectList parameter create in ExecuteJson.
In mormot.core.json.pas line 9203, function _New_ObjectList(Rtti: TRttiCustom): pointer;
I change
result := TObjectList(Rtti.ValueClass).Create;
to
result := Rtti.ValueClass.Create;
Now TObjectList is created and ArticleView method is executed, but new exception is raised on serialization of var Article: TOrmArticle in mormot.core.json
line 4966 in procedure _JS_ID
Ctxt.W.Add(Data^); here Data heve value of $09, Can not access memory at address $09.
Offline
We didn't validate MVC for mORMOt 2 yet.
I want to add some automated tests for MVC (there is none yet) to mORMot 2.
Stay tuned!
To help, I have just fixed TRttiCustom.ClassNewInstance for TObjectList.
Offline
Thanks, just to notice TOrmArticle serialization this is not MVC related
RestModel.Orm.Retrieve(ID,Article);
writeln(FormatUTF8('%', [ObjectToJson(Article)])); // << is broken, test in ArticleView
Offline
Can someone check what is a problem with serialization of TOrmArticle, problem is in procedure _JS_ID serialization of ID.
I create new test simple rest server project to exclude MVCApp, using same sqlite db and MVCModel, same problem.
TOrmArticle use FTS, I create new class TOrmArttest same as TOrmArticle (copy/paste) without FTS, same problem.
I try to change TOrmArttest = class(TOrmContent) to TOrmArttest = class(TOrm) and add all published property from inherited classes, same problem.
I'm experimenting with htmx.org, alpinejs, windi, vite project served by MVC mORMot and want to use mORMot2, some changes must be done in MCV App for serving htmx request, every URI must have 2 mustache templates, 1 for htmx request (HX-data in header of request) only returning iframe/partial and 2 for page reload/refresh full page as now.
Offline
Could you please be more precise about the "problem"?
If I understand correctly, then your Article object pointer may be invalid.
When I call ObjectToJson() on a freshly create TOrmArticle:
procedure TTestOrmCore.OrmHierarchy;
var
a: TOrmArticle;
begin
a := TOrmArticle.Create;
try
a.IDValue := 1203;
writeln(a.GetJsonValues(true,true,ooSelect));
writeln(ObjectToJson(a));
finally
a.Free;
end;
end;
then I have got the expected result:
'{"ID":1203,"CreatedAt":0,"ModifiedAt":0,"Title":"","Content":"","ContentHtml":false,"Author":null,"AuthorName":"","PublishedMonth":0,"Abstract":"","Tags":[],"LegacyHash":0}'
What does Article.GetJsonValues(true,true,ooSelect) return?
I will try and see your project sample.
Offline
OK.
I tried your sample.
Nice conversion.
After TBlogApplication.ArticleView() is executed, the nested Author: TOrmAuthor property is not properly identified as an integer, so it is handled as a pointer, therefore it fails to serialize it.
I will fix it.
Offline
@ab this simple test project work in mORMot1 but in mORMot2 raise exception
aModel := CreateModel;
try
aServer := TRestServerDB.Create(aModel,Executable.ProgramFilePath+'MVCServer.db');
try
aServer.DB.Synchronous := smNormal;
aServer.DB.LockingMode := lmExclusive;
aServer.Server.CreateMissingTables;
try
Article := TOrmArticle.Create;
try
if aServer.Orm.Retrieve(666,Article) then begin
writeln(article.GetJsonValues(true,true,ooSelect)); // This is OK Author: 1
writeln(FormatUTF8('%', [ObjectToJson(Article)])); // exception
end;
finally
Article.Free;
end;
readln;
finally
aServer.Free;
end;
finally
aModel.Free;
end;
Offline
@ab Thanks and Thanks for adding OnBeforeRender in MVC it will help a lot when using htmx, hotwire turbo or similar libraries where we need to serve different html response depend of request headers.
Offline
I have made some fixes, and also included your converted sample as https://github.com/synopse/mORMot2/tree … x/mvc-blog
Offline
Pages: 1