Fix mongo support

This commit is contained in:
Alexandre Bodin 2019-08-01 14:40:02 +02:00
parent f99e2ab683
commit 09761294e9

View File

@ -24,7 +24,7 @@ const removeUndefinedKeys = obj => _.pickBy(obj, _.negate(_.isUndefined));
module.exports = { module.exports = {
update: async function(params) { update: async function(params) {
const relationUpdates = []; const relationUpdates = [];
const populate = this.associations.map(x => x.alias).join(' '); const populate = this.associations.map(x => x.alias);
const primaryKeyValue = getValuePrimaryKey(params, this.primaryKey); const primaryKeyValue = getValuePrimaryKey(params, this.primaryKey);
const response = await this.findOne({ [this.primaryKey]: primaryKeyValue }) const response = await this.findOne({ [this.primaryKey]: primaryKeyValue })
@ -205,16 +205,18 @@ module.exports = {
return acc; return acc;
} }
case 'manyMorphToMany': case 'manyMorphToMany':
case 'manyMorphToOne': case 'manyMorphToOne': {
// Update the relational array. // Update the relational array.
acc[current] = property.map(obj => { acc[current] = property.map(obj => {
const refModel = strapi.getModel(obj.ref, obj.source);
return { return {
ref: obj.refId, ref: new mongoose.Types.ObjectId(obj.refId),
kind: obj.ref, kind: refModel.globalId,
[association.filter]: obj.field, [association.filter]: obj.field,
}; };
}); });
break; break;
}
case 'oneToManyMorph': case 'oneToManyMorph':
case 'manyToManyMorph': { case 'manyToManyMorph': {
const transformToArrayID = array => { const transformToArrayID = array => {
@ -305,16 +307,10 @@ module.exports = {
[this.primaryKey]: primaryKeyValue, [this.primaryKey]: primaryKeyValue,
}).populate(populate); }).populate(populate);
return updatedEntity; return updatedEntity.toObject ? updatedEntity.toObject() : updatedEntity;
}, },
addRelationMorph: async function(params) { addRelationMorph: async function(params) {
/*
TODO:
Test this part because it has been coded during the development of the upload feature.
However the upload doesn't need this method. It only uses the `removeRelationMorph`.
*/
let entry = await this.findOne({ let entry = await this.findOne({
[this.primaryKey]: getValuePrimaryKey(params, this.primaryKey), [this.primaryKey]: getValuePrimaryKey(params, this.primaryKey),
}); });