Parse-SDK-JS icon indicating copy to clipboard operation
Parse-SDK-JS copied to clipboard

Nested objects retourned as Parse.Object and not as registered Subclass

Open NadjibR opened this issue 4 years ago • 3 comments

New Issue Checklist

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

NadjibR avatar Aug 18 '21 15:08 NadjibR

@mtrezza

NadjibR avatar Aug 22 '21 09:08 NadjibR

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.

mtrezza avatar Aug 22 '21 10:08 mtrezza

Is there any update on this?

rocxteady avatar Jul 17 '22 12:07 rocxteady

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.

dplewis avatar Aug 29 '23 16:08 dplewis

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(...);

mtrezza avatar Aug 29 '23 19:08 mtrezza

That could work if someone was willing to do it.

dplewis avatar Aug 29 '23 19:08 dplewis

Should we keep this issue open and treat it as a feature request?

mtrezza avatar Aug 29 '23 20:08 mtrezza

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.

dplewis avatar Aug 29 '23 22:08 dplewis

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.

mtrezza avatar Aug 29 '23 22:08 mtrezza

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

hajjarjoseph avatar Apr 05 '24 10:04 hajjarjoseph