@@ -1420,9 +1420,147 @@ module.exports = session => {
1420
1420
} ) ;
1421
1421
} ) ;
1422
1422
1423
- it . skip ( 'should not update other properties than the related ones when belongsToOneRelation is inserted but the parent has noDelete: true' , ( ) => { } ) ;
1423
+ it ( 'should not update other than the relation properties when belongsToOneRelation is inserted but the parent has noUpdate: true' , ( ) => {
1424
+ const upsert = {
1425
+ id : 2 ,
1426
+
1427
+ model1Relation1 : {
1428
+ id : 3 ,
1429
+ model1Prop1 : 'this should not be written to db' ,
1430
+
1431
+ // This should cause the id=3 to be updated with the new
1432
+ // model1Id property.
1433
+ model1Relation1 : {
1434
+ model1Prop1 : 'inserted'
1435
+ }
1436
+ }
1437
+ } ;
1438
+
1439
+ return Model1 . query ( session . knex )
1440
+ . upsertGraph ( upsert , {
1441
+ noUpdate : [ 'model1Relation1' ]
1442
+ } )
1443
+ . then ( ( ) => {
1444
+ // Fetch the graph from the database.
1445
+ return Model1 . query ( session . knex )
1446
+ . findById ( 2 )
1447
+ . eager ( 'model1Relation1.model1Relation1' ) ;
1448
+ } )
1449
+ . then ( result => {
1450
+ chai . expect ( result ) . to . containSubset ( {
1451
+ id : 2 ,
1452
+
1453
+ model1Relation1 : {
1454
+ id : 3 ,
1455
+ model1Prop1 : 'belongsToOne' ,
1456
+
1457
+ model1Relation1 : {
1458
+ model1Prop1 : 'inserted'
1459
+ }
1460
+ }
1461
+ } ) ;
1462
+ } ) ;
1463
+ } ) ;
1464
+
1465
+ it ( 'should not update other than the relation properties when belongsToOneRelation is related but the parent has noUpdate: true' , ( ) => {
1466
+ const upsert = {
1467
+ id : 2 ,
1468
+
1469
+ model1Relation1 : {
1470
+ id : 3 ,
1471
+ model1Prop1 : 'this should not be written to db' ,
1472
+
1473
+ // This should cause the id=3 to be updated with the new
1474
+ // model1Id property.
1475
+ model1Relation1 : {
1476
+ id : 1
1477
+ }
1478
+ }
1479
+ } ;
1480
+
1481
+ return Model1 . query ( session . knex )
1482
+ . upsertGraph ( upsert , {
1483
+ noUpdate : [ 'model1Relation1' ] ,
1484
+ relate : [ 'model1Relation1.model1Relation1' ]
1485
+ } )
1486
+ . then ( ( ) => {
1487
+ // Fetch the graph from the database.
1488
+ return Model1 . query ( session . knex )
1489
+ . findById ( 2 )
1490
+ . eager ( 'model1Relation1.model1Relation1' ) ;
1491
+ } )
1492
+ . then ( result => {
1493
+ chai . expect ( result ) . to . containSubset ( {
1494
+ id : 2 ,
1424
1495
1425
- it . skip ( 'should not update other properties than the related ones when belongsToOneRelation is deleted but the parent has noDelete: true' , ( ) => { } ) ;
1496
+ model1Relation1 : {
1497
+ id : 3 ,
1498
+ model1Prop1 : 'belongsToOne' ,
1499
+
1500
+ model1Relation1 : {
1501
+ id : 1 ,
1502
+ model1Prop1 : 'root 1'
1503
+ }
1504
+ }
1505
+ } ) ;
1506
+ } ) ;
1507
+ } ) ;
1508
+
1509
+ it ( 'should not update other than the relation properties when belongsToOneRelation is unrelated but the parent has noUpdate: true' , ( ) => {
1510
+ const upsert1 = {
1511
+ id : 2 ,
1512
+
1513
+ model1Relation1 : {
1514
+ id : 3 ,
1515
+
1516
+ model1Relation1 : {
1517
+ id : 1
1518
+ }
1519
+ }
1520
+ } ;
1521
+
1522
+ const upsert2 = {
1523
+ id : 2 ,
1524
+
1525
+ model1Relation1 : {
1526
+ id : 3 ,
1527
+ model1Prop1 : 'this should not be written to db' ,
1528
+
1529
+ model1Relation1 : null
1530
+ }
1531
+ } ;
1532
+
1533
+ return Model1 . query ( session . knex )
1534
+ . upsertGraph ( upsert1 , {
1535
+ noUpdate : [ 'model1Relation1' ] ,
1536
+ relate : [ 'model1Relation1.model1Relation1' ]
1537
+ } )
1538
+ . then ( ( ) => {
1539
+ return Model1 . query ( session . knex ) . upsertGraph ( upsert2 , {
1540
+ noUpdate : [ 'model1Relation1' ] ,
1541
+ unrelate : [ 'model1Relation1.model1Relation1' ]
1542
+ } ) ;
1543
+ } )
1544
+ . then ( ( ) => {
1545
+ // Fetch the graph from the database.
1546
+ return Model1 . query ( session . knex )
1547
+ . findById ( 2 )
1548
+ . eager ( 'model1Relation1.model1Relation1' ) ;
1549
+ } )
1550
+ . then ( result => {
1551
+ chai . expect ( result ) . to . containSubset ( {
1552
+ id : 2 ,
1553
+
1554
+ model1Relation1 : {
1555
+ id : 3 ,
1556
+ model1Prop1 : 'belongsToOne' ,
1557
+
1558
+ model1Id : null ,
1559
+ model1Relation1 : null
1560
+ }
1561
+ } ) ;
1562
+ } ) ;
1563
+ } ) ;
1426
1564
1427
1565
it ( 'should insert with an id instead of throwing an error if `insertMissing` option is true' , ( ) => {
1428
1566
const upsert = {
@@ -1462,7 +1600,7 @@ module.exports = session => {
1462
1600
return transaction ( session . knex , trx => {
1463
1601
return Model1 . query ( trx ) . upsertGraph ( upsert , { insertMissing : true } ) ;
1464
1602
} )
1465
- . then ( result => {
1603
+ . then ( ( ) => {
1466
1604
// Fetch the graph from the database.
1467
1605
return Model1 . query ( session . knex )
1468
1606
. findById ( 2 )
0 commit comments