caseywebdev / backbone-composite-keys Goto Github PK
View Code? Open in Web Editor NEWComposite key support for Backbone. Just set your `idAttribute` to an array of attributes and you're all set.
License: MIT License
Composite key support for Backbone. Just set your `idAttribute` to an array of attributes and you're all set.
License: MIT License
This line breaks when collections define .model
as a function rather than the actual model: https://github.com/caseywebdev/backbone-composite-keys/blob/master/lib/backbone-composite-keys.coffee#L41
Backbone is always doing a PUT on models with a composite key, no matter if they are new or not. I'm assuming because of the generated ID the isNew property is always set to false.
I want to have both an integer id
, and a composite key otherId
, and have the composite key as the main id of the model.
Is there currently a way of doing this?
Backbone 0.9.9 's collection.get method was changed to separately check @_byId
and @_byCid
:
https://github.com/documentcloud/backbone/blob/0.9.9/backbone.js#L737
Unfortunately, the current master has already reverted back to the 0.9.2 behavior of having a single @_byId, so any change made would be just for 0.9.9.
I tried splitting it out like this:
return this._byId[obj.id || @model::_generateId(obj) || obj] || this._byCid[obj.cid || obj]
Only to find that @model::_generateId(obj)
causes another error when collection.model
is defined as a function (as recommended in jashkenas/backbone#793), as collection.model.prototype
isn't the model's own prototype. I've removed that specific _generateId call in my project to get it functional for now - what's the scenario where both the id and cid are blank? The final version I'm running for the moment (which seems to work for my use cases) is:
return this._byId[obj.id || obj] || this._byCid[obj.cid || obj]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.