File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " nestjs-mongo" ,
3
- "version" : " 0.14.0 " ,
3
+ "version" : " 0.14.1 " ,
4
4
"description" : " A NestJS module that provide a simple mongodb orm like" ,
5
5
"keywords" : [
6
6
" nestjs" ,
Original file line number Diff line number Diff line change @@ -390,7 +390,10 @@ export class EntityManager {
390
390
) ;
391
391
}
392
392
393
- const id : ObjectId = obj [ property ] ;
393
+ const id : ObjectId | undefined | null = obj [ property ] ;
394
+ if ( ! ( id instanceof ObjectId ) ) {
395
+ return ;
396
+ }
394
397
const filter : Filter < R > = { } ;
395
398
filter . _id = id ;
396
399
const relationship = await this . findOne < R > ( relationMetadata . type , filter , options ) ;
@@ -423,6 +426,9 @@ export class EntityManager {
423
426
}
424
427
425
428
const value = obj [ property ] ;
429
+ if ( ! Array . isArray ( value ) ) {
430
+ return [ ] ;
431
+ }
426
432
const relationshipsCursor = await this . find < R > (
427
433
relationMetadata . type ,
428
434
{
Original file line number Diff line number Diff line change @@ -216,6 +216,23 @@ describe('Relationship', () => {
216
216
)
217
217
) . toHaveLength ( 2 ) ;
218
218
} ) ;
219
+
220
+ it ( 'should return undefined for single relationship' , async ( ) => {
221
+ const entityRelationShip = new EntityRelationship ( ) ;
222
+ entityRelationShip . property = 'test_with_no_parent' ;
223
+
224
+ const notFound = await em . getRelationship ( entityRelationShip , 'parent' ) ;
225
+ expect ( notFound ) . toBeUndefined ( ) ;
226
+ } ) ;
227
+
228
+ it ( 'should return undefined for multiple children relationships' , async ( ) => {
229
+ const entityRelationShip = new EntityRelationship ( ) ;
230
+ entityRelationShip . property = 'test_with_no_children' ;
231
+
232
+ const notFound = await em . getRelationships ( entityRelationShip , 'children' ) ;
233
+ expect ( notFound ) . toBeInstanceOf ( Array ) ;
234
+ expect ( notFound ) . toHaveLength ( 0 ) ;
235
+ } ) ;
219
236
} ) ;
220
237
} ) ;
221
238
} ) ;
You can’t perform that action at this time.
0 commit comments