Skip to content

Instantly share code, notes, and snippets.

@me-ascii
Last active December 22, 2015 03:18
Show Gist options
  • Save me-ascii/6408854 to your computer and use it in GitHub Desktop.
Save me-ascii/6408854 to your computer and use it in GitHub Desktop.
var
// $ npm install [email protected]
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');
};
User = model.register( 'User', User );
var Account = function() {
this.adapter = adapter;
};
Account = model.register( '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