Skip to content

Allow Pin of unsaved Parse.Object with an unsaved, but pinned, Parse.Object pointer #1118

@BenApes

Description

@BenApes

Issue Description

When using my Parse JS SDK powered application offline, I can create a Parse Object and 'pin' it, allowing me to get the object from the local datastore when I want it, and save it later when I have connection. I cannot, however, create another object of a different class, assign the first object to a property of the second object and then pin the second object into the local datastore, as it results in the 'Cannot create a pointer to an unsaved ParseObject' error.

Steps to reproduce

  1. Initialise Parse application & enable the local datastore
Parse.initialize(environment.parseConfig.appId);
(Parse as any).serverURL = environment.parseConfig.serverUrl;
Parse.enableLocalDatastore();
  1. Define Two Classes, 'ClassA' and 'ClassB'
export class ClassA extends Parse.Object {

    constructor() {
        super('ClassA');
    }

    public get name(): string { return this.get('name'); }
    public set name(value: string) { this.set('name', value); }

}

Parse.Object.registerSubclass('ClassA', ClassA);

export class ClassB extends Parse.Object {

    constructor() {
        super('ClassB');
    }

    public get name(): string { return this.get('name'); }
    public set name(value: string) { this.set('name', value); }

    public get classA(): ClassA { return this.get('classA'); }
    public set classA(value: ClassA) { this.set('classA', value); }

}

Parse.Object.registerSubclass('ClassB', ClassB);
  1. Create instance of ClassA and pin to local datastore
const testClassA: ClassA = new ClassA();
testClassA.name = 'ABC';

await testClassA.pin();
  1. Query local datastore, find the unsaved but pinned instance of ClassA and assign to a variable
const localClassAQuery: Parse.Query<ClassA> = new Parse.Query(ClassA);
localClassAQuery.fromLocalDatastore();
localClassAQuery.equalTo('name', 'ABC');

const localClassA: ClassA = await localClassAQuery.first();
  1. Create an instance of ClassB, assign the local instance of classA to it, and attempt to pin to local datastore
    const testClassB: ClassB = new ClassB();
    testClassB.name = 'XYZ';
    testClassB.classA = localClassA;

    await testClassB.pin();

Expected Results

The instance of ClassB 'testClassB' pins to the local datastore without issue, and it's pointer to ClassA points to the local, unsaved, instance of ClassA.

Actual Outcome

The instance of ClassB does not pin to the local datastore, with the error 'Cannot create a pointer to an unsaved ParseObject'.

Environment Setup

  • Server

    • parse-server version: 4.1.0
    • Operating System: Windows 10
    • Hardware: Lenovo Laptop
    • Tested only on Localhost, but would like this to work when live on Heroku/Firebase for server/app, and when deployed using cordova to Android/iOS.
  • JS SDK

    • JS SDK version: 2.11.0
    • Application: Ionic (5+)/Angular(9+)/TypeScript(3.7.5) (front-end) && Node/TypeScript (server).

Logs/Trace

ERROR Error: "Uncaught (in promise): Error: Cannot create a pointer to an unsaved ParseObject

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions