Skip to content

ParseObject.clone() not copying object id #501

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
jaeggerr opened this issue Nov 5, 2017 · 5 comments
Closed

ParseObject.clone() not copying object id #501

jaeggerr opened this issue Nov 5, 2017 · 5 comments
Labels
type:docs Only change in the docs or README type:question Support or code-level question

Comments

@jaeggerr
Copy link

jaeggerr commented Nov 5, 2017

I am not sure if this is a bug or the expected behaviour, but I think that the clone method of ParseObjet should return an identical object and thus copy the object id.
http://parseplatform.org/Parse-SDK-JS/api/classes/Parse.Object.html#methods_clone
Other attributes seem to be correctly copied but the object id is missing.

async function testClone () {
  let myObject = new MyObject()
  myObject = await myObject.save()
  console.log(myObject.id)  // Returns an id
  myObject = myObject.clone()
  console.log(myObject.id)  // id is now undefined
}

I am using Parse 1.10.1 with Postgres.

@natanrolnik
Copy link
Contributor

natanrolnik commented Nov 6, 2017

I believe this is the intended behavior: Creates a new model with identical attributes to this one.
Imagine you want to save a new object with the same attributes as myObject, but you might change one or other attribute before saving it. This way, you keep the original object intact, and you are able to modify (and more important in this case to save) only the clone.

@natanrolnik
Copy link
Contributor

natanrolnik commented Nov 6, 2017

Yes, this is correct. Check here the test case for clone(), more specifically line 2960:

it('can be cloned', () => {
var o = new MyObject();
o.set({
size: 'large',
count: 7
});
var o2 = o.clone();
expect(o2 instanceof MyObject).toBe(true);
expect(o2.className).toBe('MyObject');
expect(o2.attributes).toEqual({
size: 'large',
count: 7
});
expect(o2.id).toBe(undefined);
expect(o.equals(o2)).toBe(false);
});
});

The object id is expected to be null by design.

@jaeggerr
Copy link
Author

jaeggerr commented Nov 6, 2017

The documentation could be a bit more clear about it.
Is there a specific git to update it?

@natanrolnik
Copy link
Contributor

This is a good question, I'm not sure - I believe the docs are generated from inline comments.
@flovilmart can you help here?

@flovilmart
Copy link
Contributor

All documentation is inline, you can provide a Pr for it. I need to investigate the documentation génération on the gh-pages branch or docs folder

@dplewis dplewis added by design type:docs Only change in the docs or README labels Sep 13, 2020
@mtrezza mtrezza added the type:question Support or code-level question label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Only change in the docs or README type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

5 participants