@@ -35,7 +35,7 @@ export function serviceMixin(entity: Entity, transform: TransformMixin, connecti
3535 public async getRelationship ( options : ServiceOptions < void > ) : Promise < ResponseRelationshipsObject > {
3636 const mainResourceName = paramCase ( this . repository . metadata . name ) ;
3737 const { relName, id } = options . route ;
38- const { needAttribute } = options . query ;
38+ const { needAttribute } = ( options . query || { needAttribute : false } ) ;
3939 const returnAttr : { [ key : string ] : Record < string , any > } = { } ;
4040 const result = await this . repository
4141 . createQueryBuilder ( mainResourceName )
@@ -477,7 +477,7 @@ export function serviceMixin(entity: Entity, transform: TransformMixin, connecti
477477
478478 await builderDeleteRelationships . addAndRemove ( idsToAdd , idsToDelete ) ;
479479
480- if ( relationObject . relationType === 'many-to-many' ) {
480+ if ( relationObject . relationType === 'many-to-many' && ( body as BaseData [ ] ) . some ( i => i . attributes ) ) {
481481 const repoTarget = this . repository . manager . getRepository < EntitySchema > ( relationObject . junctionEntityMetadata . target ) ;
482482 const currentData = await repoTarget . find ( {
483483 where : {
@@ -590,7 +590,7 @@ export function serviceMixin(entity: Entity, transform: TransformMixin, connecti
590590 const { id } = Array . isArray ( body ) ? body . shift ( ) : body ;
591591 await postBuilder . set ( id ) ;
592592 }
593- if ( relations . relationType === 'many-to-many' ) {
593+ if ( relations . relationType === 'many-to-many' && ( body as BaseData [ ] ) . some ( item => item . attributes ) ) {
594594 const repoTarget = this . repository . manager . getRepository < EntitySchema > ( relations . junctionEntityMetadata . target ) ;
595595 const currentData = await repoTarget . find ( {
596596 where : {
0 commit comments