Comparing version 2.1.24 to 2.1.25
@@ -0,1 +1,5 @@ | ||
### v2.1.25 | ||
- Fix `pool` and `debug` query options boolean check (#638) | ||
- Add `hasOne(field: 'userId', mapsTo: 'user_id')` option (#638) | ||
### v2.1.24 | ||
@@ -2,0 +6,0 @@ - Bump dependencies; Allow left/right joins in underlying db.driver.query |
@@ -18,3 +18,5 @@ var _ = require('lodash'); | ||
autoFetchLimit : opts.autoFetchLimit || 2, | ||
field : util.wrapFieldObject(opts.field, Model, Model.table, Model.properties) || util.formatField(Model, Model.table, false, false), | ||
field : util.wrapFieldObject({ | ||
field: opts.field, model: Model, altName: Model.table | ||
}) || util.formatField(Model, Model.table, false, false), | ||
getAccessor : opts.getAccessor || ("get" + assocName), | ||
@@ -21,0 +23,0 @@ setAccessor : opts.setAccessor || ("set" + assocName), |
@@ -47,3 +47,5 @@ var _ = require("lodash"); | ||
mergeId = util.convertPropToJoinKeyProp( | ||
util.wrapFieldObject(opts.mergeId, Model, Model.table, Model.properties) || | ||
util.wrapFieldObject({ | ||
field: opts.mergeId, model: Model, altName: Model.table | ||
}) || | ||
util.formatField(Model, Model.table, true, opts.reversed), | ||
@@ -54,3 +56,5 @@ { makeKey: makeKey, required: true } | ||
mergeAssocId = util.convertPropToJoinKeyProp( | ||
util.wrapFieldObject(opts.mergeAssocId, OtherModel, name, OtherModel.properties) || | ||
util.wrapFieldObject({ | ||
field: opts.mergeAssocId, model: OtherModel, altName: name | ||
}) || | ||
util.formatField(OtherModel, name, true, opts.reversed), | ||
@@ -70,3 +74,6 @@ { makeKey: makeKey, required: true } | ||
// I'm not sure the next key is used.. | ||
field : util.wrapFieldObject(opts.field, OtherModel, Model.table, OtherModel.properties) || util.formatField(Model, name, true, opts.reversed), | ||
field : util.wrapFieldObject({ | ||
field: opts.field, model: OtherModel, altName: Model.table | ||
}) || | ||
util.formatField(Model, name, true, opts.reversed), | ||
mergeTable : opts.mergeTable || (Model.table + "_" + name), | ||
@@ -73,0 +80,0 @@ mergeId : mergeId, |
@@ -42,3 +42,6 @@ var _ = require("lodash"); | ||
} else if(!association.extension) { | ||
association.field = util.wrapFieldObject(association.field, Model, Model.table, Model.properties); | ||
association.field = util.wrapFieldObject({ | ||
field: association.field, model: Model, altName: Model.table, | ||
mapsTo: association.mapsTo | ||
}); | ||
} | ||
@@ -45,0 +48,0 @@ |
@@ -74,8 +74,13 @@ var util = require("util"); | ||
opts = url.parse(opts, true); | ||
for(var k in opts.query) { | ||
opts[k] = opts.query[k]; | ||
} | ||
} else if (typeof opts == 'object') { | ||
opts = _.cloneDeep(opts); | ||
} | ||
opts.query = opts.query || {}; | ||
for(var k in opts.query) { | ||
opts.query[k] = queryParamCast(opts.query[k]); | ||
opts[k] = opts.query[k]; | ||
} | ||
if (!opts.database) { | ||
@@ -116,7 +121,5 @@ // if (!opts.pathname) { | ||
var settings = new Settings.Container(exports.settings.get('*')); | ||
var debug = extractOption(opts, "debug"); | ||
var pool = extractOption(opts, "pool"); | ||
var driver = new Driver(opts, null, { | ||
debug : (debug !== null ? ((debug === "false" || debug === "0") ? false : true) : settings.get("connection.debug")), | ||
pool : (pool !== null ? ((pool === "false" || pool === "0") ? false : true) : settings.get("connection.pool")), | ||
debug : 'debug' in opts.query ? opts.query.debug : settings.get("connection.debug"), | ||
pool : 'pool' in opts.query ? opts.query.pool : settings.get("connection.pool"), | ||
settings : settings | ||
@@ -397,17 +400,14 @@ }); | ||
function extractOption(opts, key) { | ||
if (!opts.query || !opts.query.hasOwnProperty(key)) { | ||
return null; | ||
function queryParamCast (val) { | ||
if (typeof val == 'string') { | ||
switch (val) { | ||
case '1': | ||
case 'true': | ||
return true; | ||
case '0': | ||
case 'false': | ||
return false; | ||
} | ||
} | ||
var opt = opts.query[key]; | ||
delete opts.query[key]; | ||
if (opts.href) { | ||
opts.href = opts.href.replace(new RegExp(key + "=[^&]+&?"), ""); | ||
} | ||
if (opts.search) { | ||
opts.search = opts.search.replace(new RegExp(key + "=[^&]+&?"), ""); | ||
} | ||
return opt; | ||
return val; | ||
} |
@@ -161,30 +161,39 @@ var _ = require('lodash') | ||
exports.wrapFieldObject = function (obj, model, altName, alternatives) { | ||
if (!obj) { | ||
var assoc_key = model.settings.get("properties.association_key"); | ||
exports.wrapFieldObject = function (params) { | ||
if (!params.field) { | ||
var assoc_key = params.model.settings.get("properties.association_key"); | ||
if (typeof assoc_key === "function") { | ||
obj = assoc_key(altName.toLowerCase(), model.id[0]); | ||
params.field = assoc_key(params.altName.toLowerCase(), params.model.id[0]); | ||
} else { | ||
obj = assoc_key.replace("{name}", altName.toLowerCase()) | ||
.replace("{field}", model.id[0]); | ||
params.field = assoc_key.replace("{name}", params.altName.toLowerCase()) | ||
.replace("{field}", params.model.id[0]); | ||
} | ||
} | ||
for (var k in obj) { | ||
if (!/[0-9]+/.test(k) && obj.hasOwnProperty(k)) { | ||
return obj; | ||
if (typeof params.field == 'object') { | ||
for (var k in params.field) { | ||
if (!/[0-9]+/.test(k) && params.field.hasOwnProperty(k)) { | ||
return params.field; | ||
} | ||
} | ||
} | ||
var new_obj = {}; | ||
var newObj = {}, newProp, propPreDefined, propFromKey; | ||
new_obj[obj] = _.cloneDeep( | ||
alternatives[obj] || alternatives[model.id[0]] || { type: 'number', unsigned: true, rational: false } | ||
); | ||
new_obj[obj].name = obj; | ||
new_obj[obj].mapsTo = obj; | ||
propPreDefined = params.model.properties[params.field]; | ||
propFromKey = params.model.properties[params.model.id[0]]; | ||
newProp = { type: 'integer' }; | ||
var prop = _.cloneDeep(propPreDefined || propFromKey || newProp); | ||
return new_obj; | ||
if (!propPreDefined) { | ||
_.extend(prop, { | ||
name: params.field, mapsTo: params.mapsTo || params.field | ||
}); | ||
} | ||
newObj[params.field] = prop; | ||
return newObj; | ||
}; | ||
@@ -191,0 +200,0 @@ |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version" : "2.1.24", | ||
"version" : "2.1.25", | ||
"license" : "MIT", | ||
@@ -18,0 +18,0 @@ "homepage" : "http://dresende.github.io/node-orm2", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235158
63
6019