Skip to content

Instantly share code, notes, and snippets.

@mvegap
Created March 5, 2020 18:38
Show Gist options
  • Save mvegap/f39824b9fa15cf3cfa3c2107b82f76b1 to your computer and use it in GitHub Desktop.
Save mvegap/f39824b9fa15cf3cfa3c2107b82f76b1 to your computer and use it in GitHub Desktop.
model-tutor.js
module.exports = (sequelize, DataTypes) => {
const Tutor = sequelize.define('Tutor', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER,
},
colaboradorId: {
allowNull: false,
type: DataTypes.INTEGER,
},
universidadId: {
allowNull: false,
type: DataTypes.INTEGER,
},
cicloUniversidadId: {
allowNull: false,
type: DataTypes.INTEGER,
},
estiloAprendizajeId: {
allowNull: true,
type: DataTypes.INTEGER,
},
interesId: {
allowNull: true,
type: DataTypes.INTEGER,
},
tipoPersonalidadId: {
allowNull: true,
type: DataTypes.INTEGER,
},
actualizarDatos: {
allowNull: false,
type: DataTypes.ENUM('S', 'N'),
defaultValue: 'S',
},
donacionMensual: {
allowNull: true,
type: DataTypes.TINYINT,
},
montoDonacion: {
allowNull: true,
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
paranoid: true,
version: true,
freezeTableName: true,
});
Tutor.associate = function (models) {
Tutor.belongsTo(models.Colaborador, {
as: 'Colaborador',
foreignKey: 'colaboradorId',
targetKey: 'id',
});
Tutor.belongsTo(models.Universidad, {
as: 'Universidad',
foreignKey: 'universidadId',
targetKey: 'id',
});
Tutor.belongsTo(models.EstiloAprendizaje, {
as: 'EstiloAprendizaje',
foreignKey: 'estiloAprendizajeId',
targetKey: 'id',
});
Tutor.belongsTo(models.Interes, {
as: 'Interes',
foreignKey: 'interesId',
targetKey: 'id',
});
Tutor.belongsTo(models.TipoPersonalidad, {
as: 'TipoPersonalidad',
foreignKey: 'tipoPersonalidadId',
targetKey: 'id',
});
};
return Tutor;
};
@tylrhas
Copy link

tylrhas commented Mar 5, 2020

Try This module.exports = (sequelize, DataTypes) => { const Tutor = sequelize.define('Tutor', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: DataTypes.INTEGER, }, colaboradorId: { allowNull: false, type: DataTypes.INTEGER, }, universidadId: { allowNull: false, type: DataTypes.INTEGER, }, cicloUniversidadId: { allowNull: false, type: DataTypes.INTEGER, }, estiloAprendizajeId: { allowNull: true, type: DataTypes.INTEGER, }, interesId: { allowNull: true, type: DataTypes.INTEGER, }, tipoPersonalidadId: { allowNull: true, type: DataTypes.INTEGER, }, actualizarDatos: { allowNull: false, type: DataTypes.ENUM('S', 'N'), defaultValue: 'S', }, donacionMensual: { allowNull: true, type: DataTypes.TINYINT, }, montoDonacion: { allowNull: true, type: DataTypes.INTEGER, }, }, { timestamps: true, paranoid: true, version: true, freezeTableName: true, }); Tutor.associate = function (models) { Tutor.belongsTo(models.Colaborador); Tutor.belongsTo(models.Universidad); Tutor.belongsTo(models.EstiloAprendizaje); Tutor.belongsTo(models.Interes); Tutor.belongsTo(models.TipoPersonalidad); }; return Tutor; };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment