Fix update one to one mongoose relation

This commit is contained in:
Jim Laurie 2017-10-30 17:59:53 +01:00
parent e038a238e7
commit ceff284fb6
2 changed files with 6 additions and 4 deletions

View File

@ -48,8 +48,10 @@ module.exports = {
* @return {Promise}
*/
add: (values) => {
return <%= globalID %>.create(values);
add: async (values) => {
const data = await <%= globalID %>.create(_.omit(values, _.keys(_.groupBy(strapi.models.<%= id %>.associations, 'alias'))));
await strapi.hook.mongoose.load().manageRelations(strapi.models, <%= globalID %>, _.merge(_.clone(data), { values }));
return data;
},
/**

View File

@ -369,8 +369,8 @@ module.exports = function (strapi) {
if (response[current] && _.isObject(response[current]) && response[current][Model.primaryKey] !== value[current]) {
virtualFields.push(
this.manageRelations(models, Model, {
id: response[current][Model.primaryKey],
this.manageRelations(models, models[details.model || details.collection], {
_id: response[current][Model.primaryKey],
values: {
[details.via]: null
},