dresende / node-orm2

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

Extends : isInstance is undefined #636

Open queval-j opened 9 years ago

queval-j commented 9 years ago

Hi,

I'm using node-orm2 (package.json : "orm": "^2.1.24") with MongoDB and I got this error :

TypeError: Cannot read property 'isInstance' of undefined
    at ~/git/project/node_modules/orm/lib/Associations/Extend.js:152:20
    at ~/git/project/node_modules/orm/lib/Associations/Extend.js:196:14
    at ~/git/project/node_modules/orm/lib/ChainFind.js:204:13
    at Driver.<anonymous> (~/git/project/node_modules/orm/lib/Drivers/DML/mongodb.js:154:11)
    at ~/git/project/node_modules/mongodb/lib/mongodb/cursor.js:158:16
    at commandHandler ~/git/project/node_modules/mongodb/lib/mongodb/cursor.js:651:16)
    at ~/git/project/node_modules/mongodb/lib/mongodb/db.js:1670:9
    at Server.Base._callHandler (~/git/project/node_modules/mongodb/lib/mongodb/connection/base.js:382:41)
    at ~/git/project/node_modules/mongodb/lib/mongodb/connection/server.js:472:18
    at MongoReply.parseBody (~/git/project/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)

generate.js :

var account = {
    'email': 'test',
    'password': 'f90befcfa213e3ad58e77dde6c506aad9648f157',
    'salt': '3ef765ac678408fb5af9b78725a9866476b3f565',
    'active': true,
    'information': {
        'firstname': 'John',
        'lastname': 'Smith'
    }
}
Account.create(account, function (err, acc) {
    acc.setInformation(account.information, function (err, res) {
        console.log('Account('+account.email+') ->', err, acc);
        return (asyncCB());
    })
});

My Model :

var Account = db.define("account", {
    'email': { type: "text", required: true, size:255, unique: true },
    'password': { type: "text", required: true },
    'salt': { type: "text", required: true },
    'active': { type: "integer" }
},{
    validations : {
        'email': [UniqueFunc('email')]
    },
        autoFetch: true
});
Account.extendsTo("information", {
    'firstname': String,
    'lastname': String
});

Can you tell me if I'm doing something wrong or if it's a bug ? Thanks.

dawadam commented 7 years ago

I had the same message by passing in parameter an empty value instead of a model instance.

dxg commented 7 years ago

I recently added a test which fails on mongo with the same error: https://github.com/dresende/node-orm2/pull/761/files#diff-aca78ee838dffd820b4904bd678d152cR279

If someone can figure out why it fails, that would be a good start to fixing this.