Add card and character tables
This commit is contained in:
34
models/card.js
Normal file
34
models/card.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
const {
|
||||
Model
|
||||
} = require('sequelize');
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Card extends Model {
|
||||
/**
|
||||
* Helper method for defining associations.
|
||||
* This method is not a part of Sequelize lifecycle.
|
||||
* The `models/index` file will call this method automatically.
|
||||
*/
|
||||
static associate(models) {
|
||||
Card.belongsTo(models.Character, {
|
||||
foreignKey: 'characterID',
|
||||
as: 'character'
|
||||
});
|
||||
Card.belongsTo(models.User, {
|
||||
foreignKey: 'ownerID',
|
||||
key: 'userId',
|
||||
as: 'owner'
|
||||
});
|
||||
}
|
||||
}
|
||||
Card.init({
|
||||
ownerID: DataTypes.STRING,
|
||||
identifier: DataTypes.STRING,
|
||||
characterID: DataTypes.INTEGER,
|
||||
enabled: { type: DataTypes.BOOLEAN, defaultValue: true }
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Card',
|
||||
});
|
||||
return Card;
|
||||
};
|
||||
30
models/character.js
Normal file
30
models/character.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
const {
|
||||
Model
|
||||
} = require('sequelize');
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Character extends Model {
|
||||
/**
|
||||
* Helper method for defining associations.
|
||||
* This method is not a part of Sequelize lifecycle.
|
||||
* The `models/index` file will call this method automatically.
|
||||
*/
|
||||
static associate(models) {
|
||||
Character.hasMany(models.Card, {
|
||||
foreignKey: 'characterID',
|
||||
as: 'cards'
|
||||
});
|
||||
}
|
||||
}
|
||||
Character.init({
|
||||
name: DataTypes.STRING,
|
||||
rarity: DataTypes.INTEGER,
|
||||
description: DataTypes.STRING,
|
||||
imageURL: DataTypes.STRING,
|
||||
imageHash: DataTypes.STRING
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Character',
|
||||
});
|
||||
return Character;
|
||||
};
|
||||
Reference in New Issue
Block a user