hapi-sequelize-crud/test/fixtures/models/player.js

40 lines
759 B
JavaScript
Raw Normal View History

export default (sequelize, DataTypes) => {
return sequelize.define('Player', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: DataTypes.STRING,
teamId: DataTypes.INTEGER,
2016-10-28 04:01:32 +00:00
active: DataTypes.BOOLEAN,
}, {
classMethods: {
associate: (models) => {
models.Player.belongsTo(models.Team, {
foreignKey: { name: 'teamId' },
});
},
},
2016-10-28 04:01:32 +00:00
scopes: {
returnsOne: {
where: {
active: true,
},
},
returnsNone: {
where: {
name: 'notaname',
},
},
returnsAll: {
where: {
name: {
$ne: 'notaname',
},
},
},
2016-10-28 04:01:32 +00:00
},
});
};