I have been looking for information about how can we build relationship in Backbone and came across following two nice plugins:
Both seems to have exist more than two years and seems to be stable. However, Backbone-relational
outshines against Backbone-associations
in following terms:
one-to-one, one-to-many, many-to-one
as we have in DatabaseBackbone.js
) on first glanceSince, I haven't had time to go through both the plugins extensively, I would like to know from the experienced person following things:
Biggest difference is that Backbone-relational
fobids creating multiple instances of same model with identical ids. Consider:
let Person = Backbone.RelationalModel.extend({
relations: [
type: Backbone.HasMany,
key: 'likes_movies',
relatedModel: 'Movie'
]
});
let peter = new Person({
likes_movies: [{id: 1, title: 'Fargo'}, {id: 2, title: 'Adams Family'}]
);
let john = new Person({
likes_movies: [{id: 1, title: 'Fargo'}, {id: 2, title: 'Adams Family'}]
);
// Change title of one of Peter's movies
peter.get('likes_movies').get(1).set('title', 'Fargo 2 (Sequel)');
// John's corresponding movie will have changed its name
console.log(john.get('likes_movies').get(1)); // Fargo 2 (Sequel)
If rewritten for Backbone-associations
, the movie title for John wouldn't have changed. This can be considered a feature or a disadvantage, depending on how you look at it.
Besides this, both libraries are very similar, except that development of Backbone-associations
seems to have stopped almost a year ago.
Actually, based on both GitHub pulse (activity indicator), Backbone-relational community seems much more active.
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