@@ -18,6 +18,7 @@ import {
18
18
} from "../fixtures"
19
19
20
20
import { Model , Attr , HasOne , HasMany , BelongsTo } from "../../src/decorators"
21
+ import { eq } from 'lodash-es' ;
21
22
22
23
// Accessing private property in unit tests so we need a type-loose conversion function
23
24
const modelAttrs = ( model : JSORMBase ) : Record < string , any > =>
@@ -1426,6 +1427,24 @@ describe("Model", () => {
1426
1427
descriptor = Object . getOwnPropertyDescriptor ( duped , 'relationships' ) as PropertyDescriptor
1427
1428
expect ( descriptor . enumerable ) . to . eq ( false )
1428
1429
} )
1430
+
1431
+ // NB: does NOT dupe the relationships
1432
+ describe ( "when nested relationships" , ( ) => {
1433
+ it ( "still works" , ( ) => {
1434
+ let author = new Author ( { firstName : "Stephen" } )
1435
+ author . isPersisted = true
1436
+ let genre = new Genre ( { name : 'Horror' } )
1437
+ genre . isPersisted = true
1438
+ let book1 = new Book ( { genre } )
1439
+ book1 . isPersisted = true
1440
+ author . books = [ book1 ]
1441
+ let duped = author . dup ( )
1442
+ expect ( duped . books ) . to . deep . eq ( [ book1 ] )
1443
+ expect ( duped . books [ 0 ] . isPersisted ) . to . eq ( true )
1444
+ expect ( duped . books [ 0 ] . genre ) . to . eq ( genre )
1445
+ expect ( duped . books [ 0 ] . genre . isPersisted ) . to . eq ( true )
1446
+ } )
1447
+ } )
1429
1448
} )
1430
1449
1431
1450
describe ( "#fetchOptions" , ( ) => {
0 commit comments