Merge branch 'master' into strapi-upload-rackspace

This commit is contained in:
Pongstr Ordillo 2018-04-24 11:45:07 +03:00 committed by GitHub
commit 2931ad5315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View File

@ -116,6 +116,11 @@ module.exports = function (strapi) {
[`${association.via}.${association.filter}`]: association.alias,
[`${association.via}.kind`]: definition.globalId
}
// Select last related to an entity.
this._mongooseOptions.populate[association.alias].options = {
sort: '-createdAt'
}
} else {
this._mongooseOptions.populate[association.alias].path = `${association.alias}.ref`;
}
@ -180,6 +185,7 @@ module.exports = function (strapi) {
break;
case 'manyMorphToMany':
case 'manyMorphToOne':
returned[association.alias] = returned[association.alias].map(obj => obj.ref);
break;
default:

View File

@ -235,7 +235,7 @@ module.exports = {
})
}
if (association.type === 'model') {
if (association.type === 'model' || (association.type === 'collection' && _.isObject(array))) {
return _.isEmpty(array) ? [] : transformToArrayID([array]);
}

View File

@ -211,21 +211,21 @@ module.exports = {
case 'manyToManyMorph':
const transformToArrayID = (array) => {
if (_.isArray(array)) {
return array.map(value => {
if (_.isPlainObject(value)) {
return value._id || value.id;
}
return array.map(value => {
if (_.isPlainObject(value)) {
return value._id || value.id;
}
return value;
})
}
return value;
})
}
if (association.type === 'model') {
return _.isEmpty(array) ? [] : transformToArrayID([array]);
}
if (association.type === 'model' || (association.type === 'collection' && _.isObject(array))) {
return _.isEmpty(array) ? [] : transformToArrayID([array]);
}
return [];
};
return [];
};
// Compare array of ID to find deleted files.
const currentValue = transformToArrayID(response[current]).map(id => id.toString());