Fix for null values with manyToMany and manyWay

This commit is contained in:
Jelmer Visser 2019-09-26 16:07:53 +02:00
parent 8ac65379e6
commit 3111ee4942
2 changed files with 4 additions and 6 deletions

View File

@ -159,7 +159,7 @@ module.exports = {
return _.set(
acc,
current,
property.map(val => val[assocModel.primaryKey] || val)
property ? property.map(val => val[assocModel.primaryKey] || val) : property
);
}
@ -187,12 +187,12 @@ module.exports = {
return assocModel.updateMany(
{
[assocModel.primaryKey]: {
$in: property.map(
$in: property ? property.map(
val =>
new mongoose.Types.ObjectId(
val[assocModel.primaryKey] || val
)
),
) : property,
},
},
{

View File

@ -172,9 +172,7 @@ const buildAssocResolvers = (model, name, { plugin }) => {
_.set(
queryOpts,
['query', ref.primaryKey],
obj[association.alias].map(val => val[ref.primaryKey] || val) ||
[]
);
(obj[association.alias] ? obj[association.alias].map(val => val[ref.primaryKey] || val) : []));
} else {
_.set(queryOpts, ['query', association.via], obj[ref.primaryKey]);
}