Backbone-relational icon indicating copy to clipboard operation
Backbone-relational copied to clipboard

id duplication nightmare

Open josx opened this issue 12 years ago • 2 comments

Hi all! I am searching on server with backbone collection (with related models), so every time someone search I do a:

collection.fecth();

The problem is that i cant search twice something beacuse I am getting a duplicte Id. It is already on store but it is the same object, is there a way to avoid that.

Maybe If the object on collection is the same on the store dont throw duplicate id exception.

I know that already exist findOrCreate() but i cant use it (on collections). I think Relational needs to have something at collection level doing the same thing.

josx avatar Aug 19 '13 11:08 josx

Generally a collection.fetch() won't throw that error because it will automatically reuse any model instances that exist with the same ID.

I experienced some edge cases (described in #342) where a race condition can cause this error if you're POSTing a new model and fetching the collection right around the same time. Is that what you're doing?

philfreo avatar Aug 19 '13 14:08 philfreo

I am using Backbone.io that sync models/collections over socket.io instead of using ajax.
It might be something with that I need to research more.

josx avatar Aug 19 '13 23:08 josx