Skip to content

Instantly share code, notes, and snippets.

@simong
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save simong/2b67b324886f863358c3 to your computer and use it in GitHub Desktop.

Select an option

Save simong/2b67b324886f863358c3 to your computer and use it in GitHub Desktop.
// Models
var Tenant = sequelize.define('Tenant', {
'displayName': Sequelize.STRING
});
var App = sequelize.define('App', {
'displayName': Sequelize.STRING,
'hostname': Sequelize.STRING,
'type': {
'type': Sequelize.ENUM('timetable'),
'allowNull': false
},
'enabled': {
'type': Sequelize.BOOLEAN,
'defaultValue': true
}
},
{
'instanceMethods': {
// <snip>
}
});
App.belongsTo(Tenant);
Tenant.hasMany(App);
// Logic
App.find({'where': {'hostname': 'timetable.cam.grasshopper.com'}, 'include': [Tenant]}).complete(function(err, app) {
if (err) {
console.log(err);
return;
}
console.log(JSON.stringify(app, null, 4));
/* Returns Tenant where I would expect tenant (note case)
{
"id": 1,
"displayName": "Cambridge TimeTable",
"hostname": "timetable.cam.grasshopper.com",
"type": "timetable",
"enabled": true,
"createdAt": "2014-10-19T14:31:15.114Z",
"updatedAt": "2014-10-19T14:31:15.123Z",
"TenantId": 1,
"Tenant": {
"id": 1,
"displayName": "Cambridge University",
"createdAt": "2014-10-19T14:31:15.103Z",
"updatedAt": "2014-10-19T14:31:15.103Z"
}
}
*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment