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.1.5 to 0.1.6

33

backbone-relations.js

@@ -26,4 +26,3 @@ (function () {

if (rel.hasOne) {
instance = rel.instance = new rel.hasOne();
instance.set(instance.idAttribute, this.get(rel.fk));
this._setOne(rel, instance = new rel.hasOne());
} else {

@@ -40,5 +39,9 @@ instance = rel.instance = new rel.hasMany();

} else {
instance.each(function (model) { model.set(rel.fk, self.id); });
this.listenTo(instance, 'add', function (model) {
if (model.get(rel.fk) !== this.id) model.set(rel.fk, this.id);
model.set(rel.fk, this.id);
});
this.on('change:' + this.idAttribute, function (__, val) {
instance.each(function (model) { model.set(rel.fk, val); });
});
}

@@ -66,6 +69,7 @@ }

if (rel.hasOne) {
var instance = this.get(key);
var model = val instanceof rel.hasOne ? val.attributes : val;
instance.set(model, options);
if (this.get(rel.fk) !== instance.id) attrs[rel.fk] = instance.id;
if (val instanceof rel.hasOne) {
this._setOne(rel, val, options);
} else {
this.get(key).set(val, options);
}
} else {

@@ -78,2 +82,17 @@ var models = val instanceof rel.hasMany ? val.models : val;

return set.call(this, attrs, options);
},
_setOne: function (rel, instance, options) {
if (rel.listener) this.stopListening(null, null, rel.listener);
rel.instance = instance;
var idAttr = instance.idAttribute;
if (instance.id) {
this.set(rel.fk, instance.id, options);
} else {
instance.set(idAttr, this.get(rel.fk), options);
}
rel.listener = function (__, val, options) {
this.set(rel.fk, val, options);
};
this.listenTo(instance, 'change:' + idAttr, rel.listener);
}

@@ -80,0 +99,0 @@ });

{
"name": "backbone-relations",
"version": "0.1.5",
"version": "0.1.6",
"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