2016-10-26 20:26:39 +00:00
|
|
|
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,
|
2016-10-26 20:26:39 +00:00
|
|
|
}, {
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
2016-11-02 00:38:55 +00:00
|
|
|
returnsAll: {
|
|
|
|
where: {
|
|
|
|
name: {
|
|
|
|
$ne: 'notaname',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-28 04:01:32 +00:00
|
|
|
},
|
2016-10-26 20:26:39 +00:00
|
|
|
});
|
|
|
|
};
|