@@ -827,15 +827,19 @@ describe('relations', function() {
827827 } ) ;
828828 context ( 'with filter where' , function ( ) {
829829 it ( 'returns patient where id equal to samplePatientId' , function ( done ) {
830- const whereFilter = { where : { id : samplePatientId } } ;
831- physician . patients ( whereFilter , function ( err , ch ) {
832- if ( err ) return done ( err ) ;
833- should . exist ( ch ) ;
834- ch . should . have . lengthOf ( 1 ) ;
835- ch [ 0 ] . id . should . eql ( samplePatientId ) ;
836- done ( ) ;
837- } ) ;
830+ findByFlexibleId (
831+ physician . patients . bind ( physician ) ,
832+ samplePatientId ,
833+ function ( err , ch ) {
834+ if ( err ) return done ( err ) ;
835+ should . exist ( ch ) ;
836+ ch . should . have . lengthOf ( 1 ) ;
837+ ( ch [ 0 ] . id || ch [ 0 ] . _id ) . should . eql ( samplePatientId ) ;
838+ done ( ) ;
839+ } ,
840+ ) ;
838841 } ) ;
842+
839843 it ( 'returns patient where name equal to samplePatient name' , function ( done ) {
840844 const whereFilter = { where : { name : 'a' } } ;
841845 physician . patients ( whereFilter , function ( err , ch ) {
@@ -947,6 +951,14 @@ describe('relations', function() {
947951 } ) ;
948952 } ) ;
949953 }
954+
955+ function findByFlexibleId ( scopeFn , sampleId , callback ) {
956+ scopeFn ( { where : { id : sampleId } } , function ( err , results ) {
957+ if ( err ) return callback ( err ) ;
958+ if ( results . length > 0 ) return callback ( null , results ) ;
959+ scopeFn ( { where : { _id : sampleId } } , callback ) ;
960+ } ) ;
961+ }
950962 } ) ;
951963
952964 describe ( 'find over related model with options' , function ( ) {
0 commit comments