Using %JSON.Adaptor to Export Complex Objects with relationships of 'many to many' type
Hi,
The class %JSON.Adaptor is very convenient,
I wonder if anyone faced the following scenario using it-
Exporting an object, that has a many to many relationship, and getting the details of the related objects.
For example, if we have three classes - Teachers, Students, and an intermediate class TeacherStudent .
The classes extend %JSON.Adaptor, and we would like to open a Student object, use %JSONExport, and get a JSON
That includes the details of the student and all the teachers that teach the student, something like:
{
"Id": "2",
"Name": "Noname",
"Teachers": [{
"Id": "413",
"Name": "Mr A",
}, {
"Id": "414",
"Name": "Mr B",
}
]
}
By default this is not the case, we get a list of Id's of the intermediate table:
{
"Id": "2",
"Name": "Noname",
"Teachers": [{
"Id": "1",
}, {
"Id": "2",
}
]
}
Is there any way to achieve what I described? I looked at JSON mappings documentation, that does not seem to offer a solution.
Regards,
Nael Naseraldeen