-
Notifications
You must be signed in to change notification settings - Fork 36
Unique attributes #60
Comments
Hi @TheBox193! When I've come up against this problem in the past I've just fetched the model via |
Mainly when a user navigates to a route based on username in my app I encounter the issue of duplicates. Links / routes use the 'human' friendly username instead of userid, when navigating to another route/view by username the username because the only unique identifier available. (At least in the case of a Backbone.Marionette app). It would would be nice to pass along the id with the route change in addition, but sadly I only have the username to work with. I could do a custom $.ajax (or more likely a custom Backbone.sync), however that will take additional coordination and time. If the model is already in memory and can be found by another unique attribute, ideally we can find and use it (and also avoid a duplicate). I do have some functional code running for this already, I'm liking it but going to do some further testing to make sure it is good to be shared. |
The PR #64 I put in will support
Matching by Todo:
|
I've been really enjoying the power and elegance of supermodel, thanks so much!
I have a case where I can retrieve models from my backend via an additional unique attribute other than
id
- in my caseusername
. In the cases where I.create({id: 10})
we naturally check for an existing model. However when.create({username: 'TheBox193'})
there is no id to match and thus a new model is created. I could programmatically change theidAttribute
temporarily, however that seems it might be less than ideal.Since models (for any applications) could have several unique attributes (id, username, email, etc.) would it make sense to match models based off of additional attributes to reduce duplicates? My thought would be to add a
uniqueAttributes
on the model that would define additional attributes a model could be matched by for the application.I could write a draft of this up if it would make sense.
The text was updated successfully, but these errors were encountered: