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( return _.set(
acc, acc,
current, 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( return assocModel.updateMany(
{ {
[assocModel.primaryKey]: { [assocModel.primaryKey]: {
$in: property.map( $in: property ? property.map(
val => val =>
new mongoose.Types.ObjectId( new mongoose.Types.ObjectId(
val[assocModel.primaryKey] || val val[assocModel.primaryKey] || val
) )
), ) : property,
}, },
}, },
{ {

View File

@ -172,9 +172,7 @@ const buildAssocResolvers = (model, name, { plugin }) => {
_.set( _.set(
queryOpts, queryOpts,
['query', ref.primaryKey], ['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 { } else {
_.set(queryOpts, ['query', association.via], obj[ref.primaryKey]); _.set(queryOpts, ['query', association.via], obj[ref.primaryKey]);
} }