#1 2018-10-04 17:38:16

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Join more table and get JSON code on MVC application

On MVC application i have a model like this:

TSQLTag = class(TSQLSomeone)
private

published

end;

TSQLUser = class(TSQLSomeone)
private

published

end;

TSQLContact = class(TSQLSomeone)
private

published

end;

TSQLProject = class(TSQLRecordTimeStamped)
private
  fUsers: TIntegerDynArray;
  fContacts: TIntegerDynArray; 
  fTags: TIntegerDynArray; 
...
published
  property Users: TIntegerDynArray index 1 read fUsers write fUsers;
  property Contacts: TIntegerDynArray index 2 read fContacts write fContacts 
  property Tags: TIntegerDynArray index 3 read fTags write fTags
...
end;

I need extract all projects and get all users, contacts and tags for each project. So I'd like get a JSON code like this:

"projects": 
[
    {
    "ID": 1,
    "Title": "example",
    "Code": "12345",
    "Users":
    [
        {
        "LastName": "aaa"
        "FirstName": "bbb",
        },
        {
        "LastName": "ccc"
        "FirstName": "ddd",
        }
    ],
    "Contacts":
    [
        {
        "LastName": "eee"
        "FirstName": "fff",
        },
        {
        "LastName": "ggg"
        "FirstName": "hhh",
        }
    ],
    "Tags":
    [
        {
        "Name": "iii"
        },
        {
        "Name": "lll"
        }
    ]
    }
],

Is there a way to do this?

What is the best way?

Offline

#2 2018-10-05 08:21:28

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

Re: Join more table and get JSON code on MVC application

See how MVC sample 31 works with tags.

Offline

Board footer

Powered by FluxBB