Nested objects retourned as Parse.Object and not as registered Subclass
New Issue Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
- [x] I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK.
Issue Description
When making a query with includeAll() to get nested objects, the main requested objects are returned as the subclass model, but children are returned as Parse.object.
Steps to reproduce
Parse.Query(Employee).includeAll().find(...);
Definition of Employee.ts
export default class Employee extends Parse.Object {
constructor() {
super('Employees');
}
.....
get departmentId(): Department {
return this.get('DepartmentId');
}
set departmentId(employeeDepartmentId: Department) {
this.set('DepartmentId', employeeDepartmentId);
}
}
Parse.Object.registerSubclass('Employees', Employee);
Definition of Department.ts
export default class Department extends Parse.Object {
constructor() {
super('Departments');
}
....
}
Parse.Object.registerSubclass('Departments', Department);
Actual Outcome
The departmentId in the above example is retourned as Parse.Object and not as Department.
Expected Outcome
Children of 2nd and 3rd level should be retourned as their registred classes.
Environment
Server
- Parse Server version: 4.4.0
- Operating system: Really don't know
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Back4app
Database
- System (MongoDB or Postgres): MongoDB
- Database version: 3.6
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Back4app
Client
- Parse JS SDK version: 3.3.0
Logs
@mtrezza
Thanks for reporting!
Can you please open a PR with a failing test?
We have a blog article that is especially directed towards first time contributors and a more technical Contribution Guide.
Is there any update on this?
This is expected behavior per includeAll documentation. IncludeAll doesn't support multi level because of possible infinite recursion.
Includes all nested Parse.Objects one level deep.
Wouldn't it be a valid feature request to allow multi-level with a level limit option? Then, if the schema allows it, a developer can include all down to n levels. It's the developer's responsibility then to ensure their schema is designed in a way that this produces usable results.
Parse.Query(Employee).includeAll({ levels: 3 }).find(...);
That could work if someone was willing to do it.
Should we keep this issue open and treat it as a feature request?
I would first open a feature request on the server. When I wrote includeAll I realized that there could be a performance hit for larger databases so I made it one level deep. That was 5 years ago and I think efforts have been made to improve include query performance since like https://github.com/parse-community/parse-server/pull/6501.
Sounds good, so let's keep this closed. @NadjibR, @rocxteady if you are interested in such a feature, please feel free to open a feature request in the Parse Server repository.
This is expected behavior per includeAll documentation. IncludeAll doesn't support multi level because of possible infinite recursion.
Includes all nested Parse.Objects one level deep.
const chatSessionsQuery = new Parse.Query('ChatSession');
chatSessionsQuery.include('clientUser');
const chatSessions = await chatSessionsQuery.find({ useMasterKey: true });
return chatSessions
I'm getting the same behavior even with a single include meaning that clientUser is treated as a Parse.Object and not as my registered Subclass