dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

cb is not a function #683

Closed actorius closed 8 years ago

actorius commented 8 years ago

Hello, i have a problem with running code from "Getting started" part, what i missing?

ProjectPath\node_modules\mysql\lib\protocol\Parser.js:82 throw err; ^

TypeError: cb is not a function at createNext (ProjectPath\node_modules\orm\lib\Model.js:569:12) at ProjectPath\node_modules\orm\lib\Model.js:591:6 at ProjectPath\node_modules\orm\lib\Instance.js:619:12 at Instance.saveInstanceExtra (ProjectPath\node_modules\orm\lib\Instance.js:341:19) at ProjectPath\node_modules\orm\lib\Instance.js:190:5 at Instance.runAfterSaveActions (ProjectPath\node_modules\orm\lib\Instance.js:143:3) at finish (ProjectPath\node_modules\orm\lib\Instance.js:188:4) at Instance.saveAssociations (ProjectPath\node_modules\orm\lib\Instance.js:336:11) at ProjectPath\node_modules\orm\lib\Instance.js:214:11 at Query._callback (ProjectPath\node_modules\orm\lib\Drivers\DML\mysql.js:195:10)

app.js

var orm = require("orm");

orm.connect("mysql://root:root@localhost/ard", function (err, db) {
    if (err) throw err;
    db.load("./Models/Device", function (err) {
        if (err) throw err;
        var Device = db.models.Device;
        Device.create({
            deviceSN: "T",
            firmwareVersion: "2",
            description: "Name"
        });
    });
});

./Models/Device

module.exports = function (db, cb) {
    db.define("Device", {
        deviceSN: String,
        firmwareVersion: String,
        description: String
    });
    return cb();
};
dxg commented 8 years ago

Device.create must specify a callback. See here for an example.

actorius commented 8 years ago

You right, thats work fine. Thanks for reply solution.