Skip to content
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

DS.Model.destroyRecord does not unload record from store #5006

Closed
kweng2 opened this issue Jun 5, 2017 · 6 comments · Fixed by #7258
Closed

DS.Model.destroyRecord does not unload record from store #5006

kweng2 opened this issue Jun 5, 2017 · 6 comments · Fixed by #7258

Comments

@kweng2
Copy link

kweng2 commented Jun 5, 2017

Scenario:

const memberA = store.createRecord('member', { name: 'Bob' })
await memberA.save() // server responds with an id of 5678
await memberA.destroyRecord()
const memberB = store.createRecord('member', { name: 'Bob' })
await memberB.save() // server responds with an id of 5678

Expectation:

This should work no problem, memberA and memberB should be different records, that have the same 'name'

Reality:

You cannot update the id index of an InternalModel once set. Attempted to update ${id}.

I believe what's happening is that destroyRecord is not unloading the internalModel, and therefore upon creation throwing this error

On closer inspection, it does seem that store._removeFromIdMap and internalModel.destroy only get called from the unload method

It is unclear from the docs whether destroyRecord also removes internal references

@acorncom
Copy link
Contributor

Related issue: #4972

@pangratz
Copy link
Member

pangratz commented Oct 7, 2017

I think this is fixed by #5126, so I am closing.

@kweng2 please reopen if you are still running into this issue after upgrading. Thanks!

@pangratz pangratz closed this as completed Oct 7, 2017
@SergeAstapov
Copy link
Contributor

SergeAstapov commented Oct 27, 2017

This is still an issue in [email protected]

I just hit exactly the same problem with exactly the same scenario as described in the first post.
I've tried to unload record after deletion

return coupon.destroyRecord().then(() => {
    this.get('store').unloadRecord(coupon);
});

But still got error Error: Assertion Failed: 'coupon' was saved to the server, but the response returned the new id 'XXX', which has already been used with another record.'

@maysam-tayyeb
Copy link

maysam-tayyeb commented Nov 15, 2017

I checked the unloadRecod() as follows:

unloadRecord()
{
  if (this.isDestroyed) {
    return;
  }
  this._internalModel.unloadRecord();
}

and realised it does not unload destroyed record and therefore I unloaded my record using:

model._internalModel.unloadRecord();

and it worked.

I'm sure this hack is not the good way of doing it, but it works till the right solution is proposed!

@runspired
Copy link
Contributor

This should be re-examined following the landing of #5378

@runspired
Copy link
Contributor

#5455 is in-progress to address this; however, semantics and teardown timing issues around getting deleteRecord and deleteRecord.save correct on isNew records has held it up.

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

Successfully merging a pull request may close this issue.

6 participants