adonis-lucid-mongo
Advanced tools
Comparing version 3.1.6 to 3.1.7
@@ -165,1 +165,15 @@ 'use strict' | ||
} | ||
/** | ||
* Tells whether a value exists or not, by checking for | ||
* null and undefined only | ||
* | ||
* @method existy | ||
* | ||
* @param {Mixed} value | ||
* | ||
* @return {Boolean} | ||
*/ | ||
util.existy = function (value) { | ||
return typeof (value) === 'string' ? value.trim().length > 0 : value !== undefined && value !== null | ||
} |
@@ -5,3 +5,3 @@ { | ||
"main": "index.js", | ||
"version": "3.1.6", | ||
"version": "3.1.7", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "lint": "standard", |
@@ -162,3 +162,3 @@ 'use strict' | ||
const value = relationGroups.values.find((group) => { | ||
return String(group.identity) === String(modelInstance[relationGroups.key]) | ||
return group.identity === modelInstance[relationGroups.key] | ||
}) || { value: relationGroups.defaultValue } | ||
@@ -175,2 +175,2 @@ | ||
module.exports = EagerLoad | ||
module.exports = EagerLoad |
@@ -164,3 +164,3 @@ 'use strict' | ||
*/ | ||
for (const handler of allHandlers) { | ||
for (let handler of allHandlers) { | ||
const { method } = resolver.forDir('modelHooks').resolveFunc(handler.handler) | ||
@@ -172,2 +172,2 @@ await method(...args) | ||
module.exports = Hooks | ||
module.exports = Hooks |
@@ -14,2 +14,4 @@ 'use strict' | ||
const moment = require('moment') | ||
const Hooks = require('../Hooks') | ||
const GlobalScopes = require('../GlobalScope') | ||
const GeoPoint = require('geo-point') | ||
@@ -418,2 +420,66 @@ const ObjectID = require('mongodb').ObjectID | ||
/** | ||
* Method to be called only once to boot | ||
* the model. | ||
* | ||
* NOTE: This is called automatically by the IoC | ||
* container hooks when you make use of `use()` | ||
* method. | ||
* | ||
* @method boot | ||
* | ||
* @return {void} | ||
* | ||
* @static | ||
*/ | ||
static boot () { | ||
this.hydrate() | ||
_.each(this.traits, (trait) => this.addTrait(trait)) | ||
} | ||
/** | ||
* Hydrates model static properties by re-setting | ||
* them to their original value. | ||
* | ||
* @method hydrate | ||
* | ||
* @return {void} | ||
* | ||
* @static | ||
*/ | ||
static hydrate () { | ||
/** | ||
* Model hooks for different lifecycle | ||
* events | ||
* | ||
* @type {Object} | ||
*/ | ||
this.$hooks = { | ||
before: new Hooks(), | ||
after: new Hooks() | ||
} | ||
/** | ||
* List of global query listeners for the model. | ||
* | ||
* @type {Array} | ||
*/ | ||
this.$queryListeners = [] | ||
/** | ||
* List of global query scopes. Chained before executing | ||
* query builder queries. | ||
*/ | ||
this.$globalScopes = new GlobalScopes() | ||
/** | ||
* We use the default query builder class to run queries, but as soon | ||
* as someone wants to add methods to the query builder via traits, | ||
* we need an isolated copy of query builder class just for that | ||
* model, so that the methods added via traits are not impacting | ||
* other models. | ||
*/ | ||
this.QueryBuilder = null | ||
} | ||
/** | ||
* Tells whether model instance is new or | ||
@@ -420,0 +486,0 @@ * persisted to database. |
@@ -245,66 +245,13 @@ 'use strict' | ||
/** | ||
* Method to be called only once to boot | ||
* the model. | ||
* Returns a query builder without any global scopes | ||
* | ||
* NOTE: This is called automatically by the IoC | ||
* container hooks when you make use of `use()` | ||
* method. | ||
* @method queryWithOutScopes | ||
* | ||
* @method boot | ||
* | ||
* @return {void} | ||
* | ||
* @static | ||
* @return {QueryBuilder} | ||
*/ | ||
static boot () { | ||
this.hydrate() | ||
_.each(this.traits, (trait) => this.addTrait(trait)) | ||
static queryWithOutScopes () { | ||
return this.query().ignoreScopes() | ||
} | ||
/** | ||
* Hydrates model static properties by re-setting | ||
* them to their original value. | ||
* | ||
* @method hydrate | ||
* | ||
* @return {void} | ||
* | ||
* @static | ||
*/ | ||
static hydrate () { | ||
/** | ||
* Model hooks for different lifeCycle | ||
* events | ||
* | ||
* @type {Object} | ||
*/ | ||
this.$hooks = { | ||
before: new Hooks(), | ||
after: new Hooks() | ||
} | ||
/** | ||
* List of global query listeners for the model. | ||
* | ||
* @type {Array} | ||
*/ | ||
this.$queryListeners = [] | ||
/** | ||
* List of global query scopes. Chained before executing | ||
* query builder queries. | ||
*/ | ||
this.$globalScopes = [] | ||
/** | ||
* We use the default query builder class to run queries, but as soon | ||
* as someone wants to add methods to the query builder via traits, | ||
* we need an isolated copy of query builder class just for that | ||
* model, so that the methods added via traits are not impacting | ||
* other models. | ||
*/ | ||
this.QueryBuilder = null | ||
} | ||
/** | ||
* Define a query macro to be added to query builder. | ||
@@ -377,9 +324,4 @@ * | ||
*/ | ||
static addGlobalScope (callback, name = null) { | ||
if (typeof (callback) !== 'function') { | ||
throw GE | ||
.InvalidArgumentException | ||
.invalidParameter('Model.addGlobalScope expects a closure as first parameter', callback) | ||
} | ||
this.$globalScopes.push({ callback, name }) | ||
static addGlobalScope (callback, name) { | ||
this.$globalScopes.add(callback, name) | ||
return this | ||
@@ -445,3 +387,4 @@ } | ||
static async create (payload) { | ||
const modelInstance = new this(payload) | ||
const modelInstance = new this() | ||
modelInstance.fill(payload) | ||
await modelInstance.save() | ||
@@ -468,3 +411,9 @@ return modelInstance | ||
} | ||
return Promise.all(payloadArray.map((payload) => this.create(payload))) | ||
const rows = [] | ||
for (let payload of payloadArray) { | ||
const row = await this.create(payload) | ||
rows.push(row) | ||
} | ||
return rows | ||
} | ||
@@ -471,0 +420,0 @@ |
@@ -15,2 +15,3 @@ 'use strict' | ||
const _ = require('lodash') | ||
const util = require('../../../lib/util') | ||
@@ -163,3 +164,3 @@ const methodsList = [ | ||
_validateRead () { | ||
if (!this.$primaryKeyValue || !this.parentInstance.$persisted) { | ||
if (!util.existy(this.$primaryKeyValue) || !this.parentInstance.$persisted) { | ||
throw CE.RuntimeException.unSavedModel(this.parentInstance.constructor.name) | ||
@@ -166,0 +167,0 @@ } |
313276
58
10521