-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
How to re-create a deleted record (same ID) #5014
Comments
I got the same issue while working on my undo - redo stack. The only way I found was : this.store._removeFromIdMap(this.model._internalModel) Note that you need to do that after destroyRecord. Also, it uses _ function, which means that it might not work from one version to the other. I also think destroyed record should be removed from this map automatically. |
I wonder if calling unloadRecord() would do the job here. |
Thank @sly7-7 , use |
Ha! I uses store.unloadRecord and it was not working . Going to try with
record.
…On 26 Jun 2017 8:40 am, "Huy TQ" ***@***.***> wrote:
Closed #5014 <#5014>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5014 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABNXG3PutjzYm4MKvynaBqjB4H2vdYGcks5sH1JIgaJpZM4N9VN3>
.
|
|
I also noticed just now that ember-data wreaks havoc with relationships in this situation, because there's a cache deep down in EDIT: just found the function |
This is working for me
|
I am running into this as well. Creating a new record with a specific ID (using Since the record isn't saved at the data source, I don't think |
Hi, could some open the ticket again please? I have the same problem with deleteRecord together with the id exception. |
It would be great to have this fixed. The workaround I posted above doesn't work with 3.5 any more, I'm currently looking for a new one. I wonder how many projects are constantly leaking internalModels without realizing it. EDIT: Apparently this issue is tracked in #5006. |
Same here, seems like since 3.5, my undo redo stack is broken. ( deleteRecord / createRecord with same id give me an error message about using the same id ). |
I'm on Ember 3.8 and this is still an issue, and this is still the only way that works:
|
I think this needs to be re-open, as it is still not working. |
Still not working as 3.9.2 |
You have to unload the record after persisting the deletion |
Yes, that is what I'm doing. return model.save().then(
() => model.unloadRecord()
) |
@olivierchatry with the delete call? record.deleteRecord();
record.save().then(_ => record.unloadRecord()); |
This is an "undo" action. The delete is done before saving. So yes, it is done. In this code, undo / redo are called, then save. So deleteRecord() is called ( also the whole code is working as expected on 3.4.x, started to fails in 3.5.x redo() {
this._createData()
},
undo() {
const model = this.getModel()
this._saveData()
this.onDestroyModel(model)
model.deleteRecord()
},
save() {
const model = this._modelId ? this.getModel() : this.model
if (model) {
if (model.get('isDeleted')) {
return model.save().then(
() => model.unloadRecord()
)
} else if (model.get('isDestroyed') === false ) {
return model.save().then(
() => this._modelId = model.get('id')
)
}
}
} |
Can confirm this is also an issue on ember-data 3.10.0 |
Well, there's an undocumented requirement that causes this issue. Whether it's an actual code bug or a documentation issue is up for interpretation. You have to actively |
So being looking at the code, and from what I can see, it seems if (this._scheduledDestroy === null) {
this._scheduledDestroy = Ember.run.backburner.schedule('destroy', this, '_checkForOrphanedInternalModels');
} _scheduledDestroy is used to test if someone directly call If not, then this._isDematerializing = false;
this._scheduledDestroy = null;
if (this.isDestroyed) {
return;
} My guess is that normally Was wondering if maybe somethiing was missing after the if (this.isDestroyed) {
return;
} like maybe a call to |
did anyone find a working solution for this? In ember-data 3.20.X there is no I'm having the exact same problem where I cannot seem to properly remove a record that was previously created/destroyed with same id. The record is created/deleted through a websocket update, and the addition seems to work fine using
|
I have a record with ID is sample_account. I have deleted it by using this code:
But when I re-create a new record with the same ID (sample_account), I received this error:
How can I re-create a deleted record with the same ID?
The text was updated successfully, but these errors were encountered: