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

orm

Package Overview
Dependencies
Maintainers
2
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orm - npm Package Compare versions

Comparing version 2.1.15 to 2.1.16

6

Changelog.md

@@ -0,1 +1,7 @@

### v2.1.16 - 15 Jul 2014
- Fix Model.create missing properties bug
- Add missing `var` (#523)
- Fix hasOne `required: true` when `instance.returnAllErrors` is true.
This also makes hasOne required validations messages consistent with other validation messages.
### v2.1.15 - 05 Jun 2014

@@ -2,0 +8,0 @@ - Feature: Enable plugging in custom third-party drivers (now known as adapters) (#512)

2

lib/Associations/Extend.js

@@ -7,3 +7,3 @@ var _ = require('lodash');

exports.prepare = function (db, Model, associations, association_properties, model_fields) {
exports.prepare = function (db, Model, associations) {
Model.extendsTo = function (name, properties, opts) {

@@ -10,0 +10,0 @@ opts = opts || {};

@@ -6,3 +6,3 @@ var _ = require("lodash");

exports.prepare = function (Model, associations, association_properties, model_fields) {
exports.prepare = function (Model, associations) {
Model.hasOne = function () {

@@ -45,3 +45,7 @@ var assocName;

}
util.convertPropToJoinKeyProp(association.field, { makeKey: false, required: false });
util.convertPropToJoinKeyProp(association.field, {
makeKey: false, required: association.required
});
for (var k in Accessors) {

@@ -58,7 +62,7 @@ if (!association.hasOwnProperty(k + "Accessor")) {

}
association_properties.push(k);
if (!association.reversed) {
Model.allProperties[k] = _.omit(association.field[k], 'klass');
Model.allProperties[k].klass = 'hasOne';
model_fields.push(k);
Model.addProperty(
_.extend({}, association.field[k], { klass: 'hasOne' }),
false
);
}

@@ -65,0 +69,0 @@ }

@@ -48,22 +48,2 @@ var Utilities = require("./Utilities");

for (i = 0; i < opts.one_associations.length; i++) {
for (k in opts.one_associations[i].field) {
if (opts.one_associations[i].required && opts.data[k] === null) {
var err = new Error("Property required");
err.field = k;
err.value = opts.data[k];
err.msg = "Property required";
err.type = "validation";
err.model = Model.table;
if (!Model.settings.get("instance.returnAllErrors")) {
return cb(err);
}
errors.push(err);
}
}
}
var checks = new enforce.Enforce({

@@ -76,4 +56,4 @@ returnAllErrors : Model.settings.get("instance.returnAllErrors")

if (Model.properties[k]) {
required = Model.properties[k].required;
if (Model.allProperties[k]) {
required = Model.allProperties[k].required;
} else {

@@ -87,2 +67,3 @@ for (i = 0; i < opts.one_associations.length; i++) {

}
if (!required && instance[k] == null) {

@@ -728,30 +709,22 @@ continue; // avoid validating if property is not required and is "empty"

for (i = 0; i < opts.one_associations.length; i++) {
var asc = opts.one_associations[i];
var asc = opts.one_associations[i];
if (!asc.reversed && !asc.extension) {
for (k in opts.one_associations[i].field) {
if (!opts.data.hasOwnProperty(k)) {
addInstanceProperty(k);
}
}
for (k in asc.field) {
if (!opts.data.hasOwnProperty(k)) {
addInstanceProperty(k);
}
}
}
if (opts.data.hasOwnProperty(asc.name)) {
if (opts.data[asc.name] instanceof Object) {
if (opts.data[asc.name].isInstance) {
instance[asc.name] = opts.data[asc.name];
} else {
var instanceInit = {};
var usedChance = false;
for (k in opts.one_associations[i].id) {
if (!data.hasOwnProperty(k) && !usedChance) {
instanceInit[k] = opts.data[asc.name];
usedChance = true;
} else {
instanceInit[k] = opts.data[k];
}
}
if (asc.name in opts.data) {
var d = opts.data[asc.name];
var mapper = function (obj) {
return obj.isInstance ? obj : new asc.model(obj);
};
instance[asc.name] = new opts.one_associations[i].model(instanceInit);
}
if (Array.isArray(d)) {
instance[asc.name] = d.map(mapper);
} else {
instance[asc.name] = mapper(d);
}

@@ -758,0 +731,0 @@ delete opts.data[asc.name];

@@ -202,2 +202,3 @@ var _ = require("lodash");

model.settings = opts.settings;
model.keys = opts.keys;

@@ -623,2 +624,64 @@ model.drop = function (cb) {

model.prependValidation = function (key, validation) {
if(opts.validations.hasOwnProperty(key)) {
opts.validations[key].splice(0, 0, validation);
} else {
opts.validations[key] = [validation];
}
};
var currFields = {};
model.addProperty = function (propIn, options) {
var cType;
var prop = Property.normalize({
prop: propIn, name: (options && options.name || propIn.name),
customTypes: opts.db.customTypes, settings: opts.settings
});
// Maintains backwards compatibility
if (opts.keys.indexOf(k) != -1) {
prop.key = true;
} else if (prop.key) {
opts.keys.push(k);
}
if (options && options.klass) {
prop.klass = options.klass;
}
switch (prop.klass) {
case 'primary':
opts.properties[prop.name] = prop;
break;
case 'hasOne':
association_properties.push(prop.name)
break;
}
allProperties[prop.name] = prop;
fieldToPropertyMap[prop.mapsTo] = prop;
if (prop.required) {
model.prependValidation(prop.name, Validators.required());
}
if (prop.key && prop.klass == 'primary') {
keyProperties.push(prop);
}
if (prop.lazyload !== true && !currFields[prop.name]) {
currFields[prop.name] = true;
if ((cType = opts.db.customTypes[prop.type]) && cType.datastoreGet) {
model_fields.push({
a: prop.mapsTo, sql: cType.datastoreGet(prop, opts.db.driver.query)
});
} else {
model_fields.push(prop.mapsTo);
}
}
return prop;
};
Object.defineProperty(model, "table", {

@@ -632,6 +695,2 @@ value: opts.table,

});
Object.defineProperty(model, "properties", {
value: opts.properties,
enumerable: false
});
Object.defineProperty(model, "uid", {

@@ -649,12 +708,7 @@ value: opts.driver.uid + "/" + opts.table + "/" + opts.keys.join("/"),

var currFields = {}, cType, name;
// If no keys are defined add the default one
if (opts.keys.length == 0 && !_.any(opts.properties, { key: true })) {
name = opts.settings.get("properties.primary_key");
opts.properties[name] = Property.normalize({
prop: { type: 'serial', key: true, required: false, klass: 'key' },
name: name, customTypes: opts.db.customTypes, settings: opts.settings
});
opts.properties[opts.settings.get("properties.primary_key")] = {
type: 'serial', key: true, required: false, klass: 'primary'
};
}

@@ -664,37 +718,3 @@

for (k in opts.properties) {
var prop = opts.properties[k] = Property.normalize({
prop: opts.properties[k], name: k,
customTypes: opts.db.customTypes, settings: opts.settings
});
prop.klass = 'primary';
allProperties[k] = prop;
fieldToPropertyMap[prop.mapsTo] = prop;
if (opts.keys.indexOf(k) != -1) {
prop.key = true;
} else if (prop.key) {
opts.keys.push(k);
}
if (prop.key) {
keyProperties.push(prop);
}
if (prop.lazyload !== true && !currFields[k]) {
currFields[k] = true;
if ((cType = opts.db.customTypes[prop.type]) && cType.datastoreGet) {
model_fields.push({
a: prop.mapsTo, sql: cType.datastoreGet(prop, opts.db.driver.query)
});
} else {
model_fields.push(prop.mapsTo);
}
}
if (prop.required) {
// Prepend `required` validation
if(opts.validations.hasOwnProperty(k)) {
opts.validations[k].splice(0, 0, Validators.required());
} else {
opts.validations[k] = [Validators.required()];
}
}
model.addProperty(opts.properties[k], { name: k, klass: 'primary' });
}

@@ -711,3 +731,3 @@

OneAssociation.prepare(model, one_associations, association_properties, model_fields);
OneAssociation.prepare(model, one_associations);
ManyAssociation.prepare(opts.db, model, many_associations);

@@ -714,0 +734,0 @@ ExtendAssociation.prepare(opts.db, model, extend_associations);

@@ -1,2 +0,2 @@

_ = require('lodash')
var _ = require('lodash')

@@ -3,0 +3,0 @@ /**

@@ -15,3 +15,3 @@ {

],
"version" : "2.1.15",
"version" : "2.1.16",
"license" : "MIT",

@@ -42,3 +42,3 @@ "homepage" : "http://dresende.github.io/node-orm2",

"sql-query" : "git+https://github.com/dresende/node-sql-query.git#v0.1.21",
"sql-ddl-sync" : "git+https://github.com/dresende/node-sql-ddl-sync.git#v0.3.7",
"sql-ddl-sync" : "git+https://github.com/dresende/node-sql-ddl-sync.git#v0.3.8",
"hat" : "0.0.3",

@@ -45,0 +45,0 @@ "lodash" : "2.4.1"

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