@@ -601,7 +601,7 @@ function tests(dbName, dbType) {
601
601
singular : 'post' ,
602
602
plural : 'posts'
603
603
} ] ) ;
604
-
604
+
605
605
var attachment ;
606
606
if ( process . browser ) {
607
607
attachment = blobUtil . createBlob ( [ 'Is there life on Mars?' ] ) ;
@@ -628,7 +628,7 @@ function tests(dbName, dbType) {
628
628
post . attachments . foo . content_type . should . equal ( 'text/plain' ) ;
629
629
} ) ;
630
630
} ) ;
631
-
631
+
632
632
it ( 'When updating the existing document, keeps the attachment' , function ( ) {
633
633
db . setSchema ( [ {
634
634
singular : 'post' ,
@@ -669,7 +669,7 @@ function tests(dbName, dbType) {
669
669
post . attachments . foo . content_type . should . equal ( 'text/plain' ) ;
670
670
} ) ;
671
671
} ) ;
672
-
672
+
673
673
it ( 'Removes the attachment through removal of attachments field' , function ( ) {
674
674
db . setSchema ( [ {
675
675
singular : 'post' ,
@@ -1401,6 +1401,77 @@ function tests(dbName, dbType) {
1401
1401
} ) ;
1402
1402
} ) ;
1403
1403
1404
+ it ( 'should fetch all authors even with empty relations' , function ( ) {
1405
+ db . setSchema ( [
1406
+ {
1407
+ singular : 'author' ,
1408
+ plural : 'authors' ,
1409
+ relations : {
1410
+ 'books' : { hasMany : 'book' }
1411
+ }
1412
+ } ,
1413
+ {
1414
+ singular : 'book' ,
1415
+ plural : 'books' ,
1416
+ relations : {
1417
+ 'authors' : { hasMany : 'author' }
1418
+ }
1419
+ }
1420
+ ] ) ;
1421
+
1422
+ return db . rel . save ( 'author' , {
1423
+ name : 'Stephen King' ,
1424
+ id : 19 ,
1425
+ books : [ 1 ]
1426
+ } ) . then ( function ( ) {
1427
+ return db . rel . save ( 'author' , {
1428
+ name : 'Peter Straub' ,
1429
+ id : 2 ,
1430
+ books : [ ]
1431
+ } ) ;
1432
+ } ) . then ( function ( ) {
1433
+ return db . rel . save ( 'book' , {
1434
+ title : 'It' ,
1435
+ id : 1 ,
1436
+ authors : [ 19 ]
1437
+ } ) ;
1438
+ } ) . then ( function ( ) {
1439
+ return db . rel . find ( 'authors' ) ;
1440
+ } ) . then ( function ( res ) {
1441
+ [ 'authors' , 'books' ] . forEach ( function ( type ) {
1442
+ res [ type ] . forEach ( function ( obj ) {
1443
+ obj . rev . should . be . a ( 'string' ) ;
1444
+ delete obj . rev ;
1445
+ } ) ;
1446
+ } ) ;
1447
+ res . should . deep . equal ( {
1448
+ "authors" : [
1449
+ {
1450
+ "name" : "Peter Straub" ,
1451
+ "books" : [ ] ,
1452
+ "id" : 2
1453
+ } ,
1454
+ {
1455
+ "name" : "Stephen King" ,
1456
+ "books" : [
1457
+ 1
1458
+ ] ,
1459
+ "id" : 19
1460
+ }
1461
+ ] ,
1462
+ "books" : [
1463
+ {
1464
+ "title" : "It" ,
1465
+ "authors" : [
1466
+ 19
1467
+ ] ,
1468
+ "id" : 1
1469
+ }
1470
+ ]
1471
+ } ) ;
1472
+ } ) ;
1473
+ } ) ;
1474
+
1404
1475
it ( 'does one-to-many' , function ( ) {
1405
1476
db . setSchema ( [
1406
1477
{
@@ -1888,7 +1959,7 @@ function tests(dbName, dbType) {
1888
1959
] ) ;
1889
1960
} ) ;
1890
1961
} ) ;
1891
-
1962
+
1892
1963
it ( 'should pass along options' , function ( ) {
1893
1964
1894
1965
db . setSchema ( [ {
@@ -1925,7 +1996,7 @@ function tests(dbName, dbType) {
1925
1996
} ) ;
1926
1997
} ) ;
1927
1998
} ) ;
1928
-
1999
+
1929
2000
it ( 'should pass along options, including startkey' , function ( ) {
1930
2001
1931
2002
db . setSchema ( [ {
@@ -1945,9 +2016,9 @@ function tests(dbName, dbType) {
1945
2016
id : 2
1946
2017
} ) ;
1947
2018
} ) . then ( function ( ) {
1948
-
2019
+
1949
2020
return db . rel . find ( 'post' , {
1950
- startkey : 2 ,
2021
+ startkey : 2 ,
1951
2022
limit : 1
1952
2023
} ) ;
1953
2024
} ) . then ( function ( res ) {
@@ -1965,7 +2036,7 @@ function tests(dbName, dbType) {
1965
2036
]
1966
2037
} ) ;
1967
2038
} ) ;
1968
- } ) ;
2039
+ } ) ;
1969
2040
1970
2041
it ( 'should pass along options, including endkey' , function ( ) {
1971
2042
@@ -2006,7 +2077,7 @@ function tests(dbName, dbType) {
2006
2077
} ) ;
2007
2078
} ) ;
2008
2079
} ) ;
2009
-
2080
+
2010
2081
it ( 'should pass along options, including kip' , function ( ) {
2011
2082
2012
2083
db . setSchema ( [ {
@@ -2026,9 +2097,9 @@ function tests(dbName, dbType) {
2026
2097
id : 2
2027
2098
} ) ;
2028
2099
} ) . then ( function ( ) {
2029
-
2100
+
2030
2101
return db . rel . find ( 'post' , {
2031
- skip : 1 ,
2102
+ skip : 1 ,
2032
2103
limit : 1
2033
2104
} ) ;
2034
2105
} ) . then ( function ( res ) {
@@ -2046,6 +2117,6 @@ function tests(dbName, dbType) {
2046
2117
]
2047
2118
} ) ;
2048
2119
} ) ;
2049
- } ) ;
2050
-
2120
+ } ) ;
2121
+
2051
2122
}
0 commit comments