hooks/models.js
function(fn) {
            asyncjs.each(modelNames, function(name, _fn) {
                // get model definition
                var modelDefinition = modelDefinitions[name];
                modelDefinition.__name = name;

                // get connection info
                var connectionInfo = lib.findConnection(mycro, name);
                if (!connectionInfo) {
                    mycro.log('silly', '[models] Unable to find explicit adapter for model (' + name + ')');
                    if (!defaultConnection ) {
                        return _fn('Unable to find adapter for model (' + name + ')');
                    } else {
                        connectionInfo = defaultConnection;
                    }
                }

                // validate handler exists
                var adapter = connectionInfo.adapter;
                if (!adapter.registerModel || !_.isFunction(adapter.registerModel) || adapter.registerModel.length < 3) {
                    return _fn('Invalid adapter api: adapters should define a `registerModel` method that accepts a connection object, model definition object, and a callback');
                }

                // hand off to adapter
                var registerModelCallback = function(err, model) {
                    if (err) {
                        return _fn(err);
                    }
                    if (!model) {
                        return _fn('No model (' + name + ') returned from `adapter.registerModel`');
                    }
                    mycro.models[name] = model;
                    _fn();
                };
                if (adapter.registerModel.length === 3) {
                    return adapter.registerModel(connectionInfo.connection, modelDefinition, registerModelCallback);
                } else if (adapter.registerModel.length === 4) {
                    return adapter.registerModel(connectionInfo.connection, modelDefinition, name, registerModelCallback);
                } else {
                    return adapter.registerModel(connectionInfo.connection, modelDefinition, name, mycro, registerModelCallback);
                }
            }, fn);
        }
function(fn) {
            asyncjs.each(modelNames, function(name, _fn) {
                // get model definition
                var modelDefinition = modelDefinitions[name];
                modelDefinition.__name = name;

                // get connection info
                var connectionInfo = lib.findConnection(mycro, name);
                if (!connectionInfo) {
                    mycro.log('silly', '[models] Unable to find explicit adapter for model (' + name + ')');
                    if (!defaultConnection ) {
                        return _fn('Unable to find adapter for model (' + name + ')');
                    } else {
                        connectionInfo = defaultConnection;
                    }
                }

                // validate handler exists
                var adapter = connectionInfo.adapter;
                if (!adapter.registerModel || !_.isFunction(adapter.registerModel) || adapter.registerModel.length < 3) {
                    return _fn('Invalid adapter api: adapters should define a `registerModel` method that accepts a connection object, model definition object, and a callback');
                }

                // hand off to adapter
                var registerModelCallback = function(err, model) {
                    if (err) {
                        return _fn(err);
                    }
                    if (!model) {
                        return _fn('No model (' + name + ') returned from `adapter.registerModel`');
                    }
                    mycro.models[name] = model;
                    _fn();
                };
                if (adapter.registerModel.length === 3) {
                    return adapter.registerModel(connectionInfo.connection, modelDefinition, registerModelCallback);
                } else if (adapter.registerModel.length === 4) {
                    return adapter.registerModel(connectionInfo.connection, modelDefinition, name, registerModelCallback);
                } else {
                    return adapter.registerModel(connectionInfo.connection, modelDefinition, name, mycro, registerModelCallback);
                }
            }, fn);
        }
function ( fn ) { asyncjs . each ( modelNames , function ( name , _fn ) { // get model definition var modelDefinition = modelDefinitions [ name ] ; modelDefinition . __name = name ; // get connection info var connectionInfo = lib . findConnection ( mycro , name ) ; if ( ! connectionInfo ) { mycro . log ( 'silly' , '[models] Unable to find explicit adapter for model (' + name + ')' ) ; if ( ! defaultConnection ) { return _fn ( 'Unable to find adapter for model (' + name + ')' ) ; } else { connectionInfo = defaultConnection ; } } // validate handler exists var adapter = connectionInfo . adapter ; if ( ! adapter . registerModel || ! _ . isFunction ( adapter . registerModel ) || adapter . registerModel . length < 3 ) { return _fn ( 'Invalid adapter api: adapters should define a `registerModel` method that accepts a connection object, model definition object, and a callback' ) ; } // hand off to adapter var registerModelCallback = function ( err , model ) { if ( err ) { return _fn ( err ) ; } if ( ! model ) { return _fn ( 'No model (' + name + ') returned from `adapter.registerModel`' ) ; } mycro . models [ name ] = model ; _fn ( ) ; } ; if ( adapter . registerModel . length === 3 ) { return adapter . registerModel ( connectionInfo . connection , modelDefinition , registerModelCallback ) ; } else if ( adapter . registerModel . length === 4 ) { return adapter . registerModel ( connectionInfo . connection , modelDefinition , name , registerModelCallback ) ; } else { return adapter . registerModel ( connectionInfo . connection , modelDefinition , name , mycro , registerModelCallback ) ; } } , fn ) ; }
hand model definitions to the appropriate adapter for construction
hand model definitions to the appropriate adapter for construction