adonis-lucid-mongodb
Advanced tools
Comparing version 0.11.4 to 0.11.5
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.11.4", | ||
"version": "0.11.5", | ||
"scripts": { | ||
@@ -11,0 +11,0 @@ "lint": "standard", |
@@ -16,3 +16,2 @@ 'use strict' | ||
const ObjectID = require('mongodb').ObjectID | ||
const mquery = require('mquery') | ||
const methods = exports = module.exports = {} | ||
@@ -19,0 +18,0 @@ |
@@ -20,7 +20,18 @@ 'use strict' | ||
constructor (parent, related, determine, primaryKey, foreignKey) { | ||
/** | ||
* Creates an instance of MorphMany. | ||
* | ||
* @param {String} parent | ||
* @param {String} related | ||
* @param {String} determiner | ||
* @param {String} foreignKey | ||
* @param {String} primaryKey | ||
* | ||
* @memberOf MorphMany | ||
*/ | ||
constructor (parent, related, determiner, foreignKey, primaryKey) { | ||
super(parent, related) | ||
this.fromKey = primaryKey || this.parent.constructor.primaryKey | ||
this.toKey = foreignKey || this.parent.constructor.foreignKey | ||
this.determine = determine || 'parent' | ||
this.toKey = foreignKey || 'parentId' | ||
this.determiner = determiner || 'parentType' | ||
} | ||
@@ -44,7 +55,7 @@ | ||
const results = yield this.relatedQuery | ||
.where(`${this.determine}_type`, this.parent.constructor.name) | ||
.whereIn(`${this.determine}_id`, values).fetch() | ||
.where(this.determiner, this.parent.constructor.name) | ||
.whereIn(this.toKey, values).fetch() | ||
return results.groupBy((item) => { | ||
return item[`${this.determine}_id`] | ||
return item[this.toKey] | ||
}).mapValues(function (value) { | ||
@@ -73,4 +84,4 @@ return helpers.toCollection(value) | ||
const results = yield this.relatedQuery | ||
.where(`${this.determine}_type`, this.parent.constructor.name) | ||
.where(`${this.determine}_id`, value).fetch() | ||
.where(this.determiner, this.parent.constructor.name) | ||
.whereIn(this.toKey, value).fetch() | ||
const response = {} | ||
@@ -99,4 +110,4 @@ response[value] = results | ||
} | ||
relatedInstance.set(`${this.determine}_type`, this.parent.constructor.name) | ||
relatedInstance.set(`${this.determine}_id`, this.parent[this.fromKey]) | ||
relatedInstance.set(this.determiner, this.parent.constructor.name) | ||
relatedInstance.set(this.toKey, this.parent[this.fromKey]) | ||
return yield relatedInstance.save() | ||
@@ -103,0 +114,0 @@ } |
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
218741
7987