Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone-relations

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-relations - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

34

backbone-relations.js

@@ -19,2 +19,10 @@ (function () {

this.owner = owner;
var proto = (this.hasOne || this.hasMany.prototype.model).prototype;
if (!proto.relations) return;
var hasOne = !this.hasOne;
var fk = this.fk;
this.reverse = _.reduce(proto.relations(), function (reverse, rel, key) {
if (!rel.via && hasOne !== !rel.hasOne && fk === rel.fk) return key;
return reverse;
}, null);
};

@@ -27,4 +35,5 @@

var instance = this.instance;
if (instance && instance.id === this.owner.get(this.fk)) return instance;
this.set(instance = new this.hasOne());
var fk = this.owner.get(this.fk);
if (instance && instance.id === fk) return instance;
this.set(instance = new this.hasOne({id: fk}));
return instance;

@@ -39,11 +48,9 @@ },

var fk = this.fk;
var reverse = this.reverse;
var idAttr = val.idAttribute;
if (val.id) {
owner.set(fk, val.id, options);
} else {
val.set(idAttr, owner.get(fk), options);
}
owner.set(fk, val.id, options);
this.listenTo(val, 'change:' + idAttr, function (__, val, options) {
owner.set(fk, val, options);
});
if (reverse) val.get(reverse).add(owner);
} else {

@@ -70,4 +77,5 @@ this.get(this.key).set(val, options);

var owner = instance.owner = this.owner;
var fk = instance.fk = this.fk;
instance.fk = this.fk;
var key = this.key;
var reverse = this.reverse;
instance.url = function () {

@@ -78,10 +86,4 @@ return _.result(owner, 'url') + (urlRoot || '/' + key);

instance.via = owner.get(this.via.split('#')[0]);
} else {
instance.each(function (model) { model.set(fk, owner.id); });
owner.listenTo(instance, 'add', function (model) {
model.set(fk, owner.id);
});
owner.on('change:' + owner.idAttribute, function (__, val) {
instance.each(function (model) { model.set(fk, val); });
});
} else if (reverse) {
instance.on('add', function (model) { model.set(reverse, owner); });
}

@@ -88,0 +90,0 @@ return this.get();

{
"name": "backbone-relations",
"version": "0.3.0",
"version": "0.3.1",
"author": "Casey Foster <c@sey.me>",

@@ -5,0 +5,0 @@ "licence": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc