@@ -574,7 +574,7 @@ describe('relations', function() {
574
574
before ( function ( done ) {
575
575
db = getSchema ( ) ;
576
576
Physician = db . define ( 'Physician' , { name : String } ) ;
577
- Patient = db . define ( 'Patient' , { name : String , age : Number } ) ;
577
+ Patient = db . define ( 'Patient' , { name : String , age : Number , sequence : Number } ) ;
578
578
Appointment = db . define ( 'Appointment' , { date : { type : Date ,
579
579
default : function ( ) {
580
580
return new Date ( ) ;
@@ -734,7 +734,7 @@ describe('relations', function() {
734
734
context ( 'with filter skip' , function ( ) {
735
735
bdd . itIf ( connectorCapabilities . supportPagination !== false ,
736
736
'skips the first patient' , function ( done ) {
737
- physician . patients ( { skip : 1 } , function ( err , ch ) {
737
+ physician . patients ( { skip : 1 , order : 'sequence' } , function ( err , ch ) {
738
738
if ( err ) return done ( err ) ;
739
739
should . exist ( ch ) ;
740
740
ch . should . have . lengthOf ( 2 ) ;
@@ -767,7 +767,7 @@ describe('relations', function() {
767
767
} ) ;
768
768
context ( 'with filter limit' , function ( ) {
769
769
it ( 'limits to 1 result' , function ( done ) {
770
- physician . patients ( { limit : 1 } , function ( err , ch ) {
770
+ physician . patients ( { limit : 1 , order : 'sequence' } , function ( err , ch ) {
771
771
if ( err ) return done ( err ) ;
772
772
should . exist ( ch ) ;
773
773
ch . should . have . lengthOf ( 1 ) ;
@@ -782,7 +782,10 @@ describe('relations', function() {
782
782
} ) ;
783
783
context ( 'with filter fields' , function ( ) {
784
784
it ( 'includes field \'name\' but not \'age\'' , function ( done ) {
785
- var fieldsFilter = { fields : { name : true , age : false } } ;
785
+ var fieldsFilter = {
786
+ fields : { name : true , age : false } ,
787
+ order : 'sequence' ,
788
+ } ;
786
789
physician . patients ( fieldsFilter , function ( err , ch ) {
787
790
if ( err ) return done ( err ) ;
788
791
should . exist ( ch ) ;
@@ -832,8 +835,16 @@ describe('relations', function() {
832
835
if ( err ) return done ( err ) ;
833
836
should . exist ( ch ) ;
834
837
ch . should . have . lengthOf ( 2 ) ;
835
- var resultIdArr = [ ch [ 0 ] . id , ch [ 1 ] . id ] ;
836
- assert . deepEqual ( resultIdArr , idArr ) ;
838
+ if ( typeof idArr [ 0 ] === 'object' ) {
839
+ // mongodb returns `id` as an object
840
+ idArr [ 0 ] = idArr [ 0 ] . toString ( ) ;
841
+ idArr [ 1 ] = idArr [ 1 ] . toString ( ) ;
842
+ idArr . indexOf ( ch [ 0 ] . id . toString ( ) ) . should . not . equal ( - 1 ) ;
843
+ idArr . indexOf ( ch [ 1 ] . id . toString ( ) ) . should . not . equal ( - 1 ) ;
844
+ } else {
845
+ idArr . indexOf ( ch [ 0 ] . id ) . should . not . equal ( - 1 ) ;
846
+ idArr . indexOf ( ch [ 1 ] . id ) . should . not . equal ( - 1 ) ;
847
+ }
837
848
done ( ) ;
838
849
} ) ;
839
850
} ) ;
@@ -888,15 +899,17 @@ describe('relations', function() {
888
899
889
900
function createSampleData ( done ) {
890
901
Physician . create ( function ( err , result ) {
891
- result . patients . create ( { name : 'a' , age : '10' } , function ( err , p ) {
892
- samplePatientId = p . id ;
893
- result . patients . create ( { name : 'z' , age : '20' } , function ( ) {
894
- result . patients . create ( { name : 'c' } , function ( ) {
895
- physician = result ;
896
- done ( ) ;
897
- } ) ;
902
+ result . patients . create ( { name : 'a' , age : '10' , sequence : 1 } ,
903
+ function ( err , p ) {
904
+ samplePatientId = p . id ;
905
+ result . patients . create ( { name : 'z' , age : '20' , sequence : 2 } ,
906
+ function ( ) {
907
+ result . patients . create ( { name : 'c' , sequence : 3 } , function ( ) {
908
+ physician = result ;
909
+ done ( ) ;
910
+ } ) ;
911
+ } ) ;
898
912
} ) ;
899
- } ) ;
900
913
} ) ;
901
914
} ;
902
915
} ) ;
0 commit comments