@@ -658,6 +658,17 @@ describe('manipulation', function() {
658658 } ) ;
659659
660660 describe ( 'updateOrCreate' , function ( ) {
661+ var ds = getSchema ( ) ;
662+ var Post ;
663+
664+ before ( 'prepare "Post" model' , function ( done ) {
665+ Post = ds . define ( 'Post' , {
666+ title : { type : String , id : true } ,
667+ content : { type : String } ,
668+ } ) ;
669+ ds . automigrate ( 'Post' , done ) ;
670+ } ) ;
671+
661672 it ( 'has an alias "patchOrCreate"' , function ( ) {
662673 StubUser . updateOrCreate . should . equal ( StubUser . patchOrCreate ) ;
663674 } ) ;
@@ -716,6 +727,37 @@ describe('manipulation', function() {
716727 } ) ;
717728 } ) ;
718729
730+ it ( 'updates specific instances when PK is not an auto-generated id' , function ( done ) {
731+ Post . create ( [
732+ { title : 'postA' , content : 'contentA' } ,
733+ { title : 'postB' , content : 'contentB' } ,
734+ ] , function ( err , instance ) {
735+ if ( err ) return done ( err ) ;
736+
737+ Post . updateOrCreate ( {
738+ title : 'postA' , content : 'newContent' ,
739+ } , function ( err , instance ) {
740+ if ( err ) return done ( err ) ;
741+
742+ var result = instance . toObject ( ) ;
743+ result . should . have . properties ( {
744+ title : 'postA' ,
745+ content : 'newContent' ,
746+ } ) ;
747+ Post . find ( function ( err , posts ) {
748+ if ( err ) return done ( err ) ;
749+
750+ posts . should . have . length ( 2 ) ;
751+ posts [ 0 ] . title . should . equal ( 'postA' ) ;
752+ posts [ 0 ] . content . should . equal ( 'newContent' ) ;
753+ posts [ 1 ] . title . should . equal ( 'postB' ) ;
754+ posts [ 1 ] . content . should . equal ( 'contentB' ) ;
755+ done ( ) ;
756+ } ) ;
757+ } ) ;
758+ } ) ;
759+ } ) ;
760+
719761 it ( 'should allow save() of the created instance' , function ( done ) {
720762 Person . updateOrCreate (
721763 { id : 999 /* a new id */ , name : 'a-name' } ,
0 commit comments