File tree Expand file tree Collapse file tree 2 files changed +77
-5
lines changed
Expand file tree Collapse file tree 2 files changed +77
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ var url = require("url");
55var hat = require ( "hat" ) ;
66var Query = require ( "sql-query" ) ;
77var enforce = require ( "enforce" ) ;
8+ var _ = require ( "lodash" ) ;
89
910var Model = require ( "./Model" ) . Model ;
1011var DriverAliases = require ( "./Drivers/aliases" ) ;
@@ -254,12 +255,33 @@ ORM.prototype.close = function (cb) {
254255
255256 return this ;
256257} ;
257- ORM . prototype . load = function ( file , cb ) {
258- try {
259- return require ( Utilities . getRealPath ( file ) ) ( this , cb ) ;
260- } catch ( ex ) {
261- return cb ( ex ) ;
258+ ORM . prototype . load = function ( ) {
259+ var files = _ . flatten ( Array . prototype . slice . apply ( arguments ) ) ;
260+ var cb = function ( ) { } ;
261+
262+ if ( typeof files [ files . length - 1 ] == "function" ) {
263+ cb = files . pop ( ) ;
262264 }
265+
266+ var loadNext = function ( ) {
267+ if ( files . length === 0 ) {
268+ return cb ( ) ;
269+ }
270+
271+ var file = files . shift ( ) ;
272+
273+ try {
274+ return require ( Utilities . getRealPath ( file , 4 ) ) ( this , function ( err ) {
275+ if ( err ) return cb ( err ) ;
276+
277+ return loadNext ( ) ;
278+ } ) ;
279+ } catch ( ex ) {
280+ return cb ( ex ) ;
281+ }
282+ } . bind ( this ) ;
283+
284+ return loadNext ( ) ;
263285} ;
264286ORM . prototype . sync = function ( cb ) {
265287 var modelIds = Object . keys ( this . models ) ;
Original file line number Diff line number Diff line change @@ -129,6 +129,56 @@ describe("db.load()", function () {
129129 } ) ;
130130} ) ;
131131
132+ describe ( "db.load()" , function ( ) {
133+ var db = null ;
134+
135+ before ( function ( done ) {
136+ helper . connect ( function ( connection ) {
137+ db = connection ;
138+
139+ return done ( ) ;
140+ } ) ;
141+ } ) ;
142+
143+ after ( function ( ) {
144+ return db . close ( ) ;
145+ } ) ;
146+
147+ it ( "should be able to load more than one file" , function ( done ) {
148+ db . load ( "../support/spec_load_second" , "../support/spec_load_third" , function ( ) {
149+ db . models . should . have . property ( "person" ) ;
150+ db . models . should . have . property ( "pet" ) ;
151+
152+ return done ( ) ;
153+ } ) ;
154+ } ) ;
155+ } ) ;
156+
157+ describe ( "db.load()" , function ( ) {
158+ var db = null ;
159+
160+ before ( function ( done ) {
161+ helper . connect ( function ( connection ) {
162+ db = connection ;
163+
164+ return done ( ) ;
165+ } ) ;
166+ } ) ;
167+
168+ after ( function ( ) {
169+ return db . close ( ) ;
170+ } ) ;
171+
172+ it ( "should be able to load more than one file passed as Array" , function ( done ) {
173+ db . load ( [ "../support/spec_load_second" , "../support/spec_load_third" ] , function ( ) {
174+ db . models . should . have . property ( "person" ) ;
175+ db . models . should . have . property ( "pet" ) ;
176+
177+ return done ( ) ;
178+ } ) ;
179+ } ) ;
180+ } ) ;
181+
132182describe ( "db.serial()" , function ( ) {
133183 var db = null ;
134184
You can’t perform that action at this time.
0 commit comments