Backbone-kinship
A simple, lightweight, Backbone model adding 1-1 and 1-N relations. No shared instances, data pooling or reversed relations. It's really just a way to expand nested data into models and collections.
Creating a model with relations
var Fruits = BackboneCollection;var Robot = BackboneModel;var MyRelationalModel = BackboneRelationalModel;var myRelationalModelInstance ="myFirstRelation":"type": "banana""eatenBy": "monkey""type": "apple""eatenBy": "horse""myOtherRelation":"name": "Bender Rodriguez";
Accessing data on a related model or collection
After instantiating a Backbone.RelationalModel
you can access the related models and collections by get
ting them like so:
console;>> "banana"console;>> "Bender Rodriguez"
... or alternatively:
console;>> "Bender Rodriguez"
Events
Events are propagated from their relationships as eventName:relationshipName
. The following events also triggers a change event: "add", "remove", "change", "reset". Like so:
myRelationalModelInstance;myRelationalModelInstance;>> "change">> "add:myFirstRelation"
Backbone-kinship is released under the MIT license. Contributors: https://github.com/Oktavilla/backbone-kinship/contributors