Skip to content

Instantly share code, notes, and snippets.

@mde
Forked from me-ascii/model-hasMany-error.js
Last active December 22, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mde/6409331 to your computer and use it in GitHub Desktop.
Save mde/6409331 to your computer and use it in GitHub Desktop.
var
// $ npm install model@0.2.10
model = require( 'model'),
Adapter = require('./node_modules/model/lib/adapters/memory/').Adapter,
adapter = new Adapter({});
var User = function () {
this.adapter = adapter;
this.property('login', 'string', {required: true});
this.property('password', 'string', {required: true});
this.property('confirmPassword', 'string', {required: true});
this.hasMany('Accounts');
};
var Account = function() {
this.adapter = adapter;
};
model.registerDefinitions([
{ ctorName: 'User'
, ctor: User
}
, { ctorName: 'Account'
, ctor: Account
}
]);
model.User = User;
model.Account = Account;
var user = User.create({
login: 'asdf'
, password: 'zerb'
, confirmPassword: 'zerb'
});
user.save(function (err, data) {
if (err) {
throw err;
}
user.addAccount(Account.create({}));
user.addAccount(Account.create({}));
user.save(function (err, data) {
if (err) {
throw err;
}
user.getAccounts(function (err, data) {
if (err) {
throw err;
}
console.log('This number should be 2: ' + data.length);
});
});
});
// Its throw that error:
//
// .../node_modules/model/lib/query/query.js:184
// datatype = descr.datatype;
// ^
// TypeError: Cannot read property 'datatype' of undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment