I've a merged collection in Backbone which contains photos and albums.
To distinguish between them, i've added a field type
which is either photo
or album
. When I populate the collection, I create different models within the Collection#model
method
model: (attrs, options) ->
switch attrs.type
when 'album' then new App.Models.Album(attrs, options)
when 'photo' then new App.Models.Photo(attrs, options)
Now I've discoverd a strange bug where adding a photo and an album with the same ID (let's say 2
) results in a merge.
I've tracked this down to these LOC in the source code. It seems that it's undoable without creating a fork of Backbone itself. I've tried it but it also fails 35 tests.
I thought of 4 different ways of doing this, I don't know which of them is the better one:
photo_2
. This causes a change in the backend as well as some changes in the frontend to don't hit the server at /photos/photo_2
1000000
. This would extremely decrease the probability that a given user which has uploaded a photo with a given ID has also created an album with the same ID.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With