Skip to content

Unsaved children are not able to be saved when updating parent object #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TylerBrock opened this issue Nov 10, 2015 · 1 comment
Closed

Comments

@TylerBrock
Copy link
Contributor

Adding to our list of items in #73.

In the below code we make two classes Brand and Item. Let's say that Brands can have many Items and that this relationship is modeled by an array of Item pointers set on the "items" field for Brand.

We then create a new Item and Brand, setting the item as an array of pointer on brand.

It saves just fine. Parse realized that item is unsaved and persists it before saving brand. It follows up by saving brand and resolving the promise.

However, if we then try to add unsaved objects to the already persisted brand it becomes unable to save the unsaved objects giving the error:

"Cannot create a pointer to an unsaved ParseObject"

Setup

'use strict';

var Parse = require('parse/node');

class Brand extends Parse.Object {
  constructor(attributes, options) {
    super('Brand', attributes, options);
  }
}
Parse.Object.registerSubclass('Brand', Brand);

class Item extends Parse.Object {
  constructor(attributes, options) {
    super('Item', attributes, options);
  }
}
Parse.Object.registerSubclass('Item', Item);

Test

var item = new Item();
var brand = new Brand({items: [item]});
brand.save().then(function(savedBrand) {
  console.log('works fine');

  var item2 = new Item();
  var brandItems = brand.get('items');
  brandItems.push(item2);
  brand.set("items", brandItems);

  // parse should save unsaved items successfully here
  return brand.save().then(function(updatedBrand) {
    console.log('cool');
  });
});

This seems like a bug. It works just fine in the 1.5 SDK. Please let me know what you think. Also I'd love to help fix it if you point me in the right direction. Anything I can do to help, let me know.

fkling added a commit to fkling/astexplorer that referenced this issue Dec 10, 2015
Switching to ES6 class declarations requires to "register" the subclass
with Parse, according to the documentation:
https://parse.com/docs/js/guide#objects-parse-object.

There seems to be a bug (feature?) in Parse v1.6 where it isn't possible
anymore to add a new object to an existing collection and just save the
parent object: parse-community/Parse-SDK-JS#89.
@andrewimm
Copy link
Contributor

Resolved in 5e86f78, will be released in 1.6.14

ionisaligox72 added a commit to ionisaligox72/astexplorer that referenced this issue Aug 7, 2024
Switching to ES6 class declarations requires to "register" the subclass
with Parse, according to the documentation:
https://parse.com/docs/js/guide#objects-parse-object.

There seems to be a bug (feature?) in Parse v1.6 where it isn't possible
anymore to add a new object to an existing collection and just save the
parent object: parse-community/Parse-SDK-JS#89.
my2 added a commit to my2/astexplorer that referenced this issue Aug 13, 2024
Switching to ES6 class declarations requires to "register" the subclass
with Parse, according to the documentation:
https://parse.com/docs/js/guide#objects-parse-object.

There seems to be a bug (feature?) in Parse v1.6 where it isn't possible
anymore to add a new object to an existing collection and just save the
parent object: parse-community/Parse-SDK-JS#89.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants