adonis-lucid-mongodb
Advanced tools
Comparing version 1.0.51 to 1.0.52
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "1.0.51", | ||
"version": "1.0.52", | ||
"scripts": { | ||
@@ -11,0 +11,0 @@ "lint": "standard", |
@@ -344,4 +344,4 @@ # AdonisJS Lucid MongoDB | ||
auth: { | ||
source: Env.get('DB_AUTH_SOURCE', 'admin'), | ||
mechanism: Env.get('DB_AUTH_MECHANISM', 'MONGODB-CR') | ||
source: Env.get('DB_AUTH_SOURCE', ''), | ||
mechanism: Env.get('DB_AUTH_MECHANISM', '') | ||
} | ||
@@ -348,0 +348,0 @@ } |
@@ -148,7 +148,7 @@ 'use strict' | ||
: (process.env.DB_USER ? `${process.env.DB_USER}@` : '') | ||
const authString = (config.connection.auth && config.connection.auth.source && config.connection.auth.mechanism) | ||
? `?authSource=${config.connection.auth.source}&authMechanism=${config.connection.auth.mechanism}` | ||
: '' | ||
const connectionString = `mongodb://${security}${config.connection.host}:${config.connection.port}/${config.connection.database}${authString}` | ||
@@ -155,0 +155,0 @@ MongoClient.connect(connectionString).then(dbConnection => { |
@@ -45,3 +45,3 @@ 'use strict' | ||
this.exists = true | ||
this.original = _.clone(this.attributes) | ||
this.original = _.cloneDeep(this.attributes) | ||
return !!save | ||
@@ -87,3 +87,3 @@ } | ||
this.parsePersistance(_.omit(dirtyValues, ['$set', '$unset'])) | ||
this.original = _.clone(this.attributes) | ||
this.original = _.cloneDeep(this.attributes) | ||
} | ||
@@ -90,0 +90,0 @@ return save |
@@ -280,11 +280,26 @@ 'use strict' | ||
const pivotOtherKeys = _.map(pivots, this.pivotOtherKey) | ||
let results = yield this.relatedQuery.whereIn('_id', pivotOtherKeys).fetch() | ||
results = this._addPivotKeys(results, pivots) | ||
return results.groupBy((result) => { | ||
return _.find(pivots, pivot => { | ||
return String(pivot[this.pivotOtherKey]) === String(result._id) | ||
})[this.pivotLocalKey] | ||
}).mapValues(function (value) { | ||
return helpers.toCollection(value) | ||
}).value() | ||
const relatedInstances = yield this.relatedQuery.whereIn('_id', pivotOtherKeys).fetch() | ||
// results = this._addPivotKeys(results, pivots) | ||
const results = {} | ||
relatedInstances.value().forEach(related => { | ||
_.filter(pivots, pivot => { | ||
return String(related._id) === String(pivot[this.pivotOtherKey]) | ||
}).forEach(pivot => { | ||
const newRelated = new related.constructor() | ||
newRelated.attributes = _.cloneDeep(related.attributes) | ||
newRelated.original = _.cloneDeep(related.original) | ||
newRelated.exists = true | ||
_.forEach(this.pivotItems, (item) => { | ||
newRelated.attributes[`${this.pivotPrefix}${item}`] = _.get(pivot, item) | ||
}) | ||
results[pivot[this.pivotLocalKey]] = results[pivot[this.pivotLocalKey]] || [] | ||
results[pivot[this.pivotLocalKey]].push(newRelated) | ||
}) | ||
}) | ||
_.forEach(results, (result, key) => { | ||
results[key] = helpers.toCollection(result) | ||
}) | ||
return results | ||
} | ||
@@ -291,0 +306,0 @@ |
@@ -48,3 +48,3 @@ 'use strict' | ||
modelInstance.exists = true | ||
modelInstance.original = _.clone(modelInstance.attributes) | ||
modelInstance.original = _.cloneDeep(modelInstance.attributes) | ||
return _(modelInstance) | ||
@@ -75,3 +75,3 @@ }).value() | ||
modelInstance.exists = true | ||
modelInstance.original = _.clone(modelInstance.attributes) | ||
modelInstance.original = _.cloneDeep(modelInstance.attributes) | ||
response[value] = _(modelInstance) | ||
@@ -78,0 +78,0 @@ return response |
260818
8785