Created
March 5, 2020 18:39
-
-
Save mvegap/56fd44a1349dcf512b61952284a36c87 to your computer and use it in GitHub Desktop.
model-colaborador.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (sequelize, DataTypes) => { | |
const Colaborador = sequelize.define('Colaborador', { | |
id: { | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
type: DataTypes.INTEGER, | |
}, | |
usuarioId: { | |
allowNull: false, | |
type: DataTypes.INTEGER, | |
}, | |
nombres: { | |
allowNull: false, | |
type: DataTypes.STRING, | |
}, | |
apellidoPaterno: { | |
allowNull: false, | |
type: DataTypes.STRING, | |
}, | |
apellidoMaterno: { | |
allowNull: false, | |
type: DataTypes.STRING, | |
}, | |
nombresCompletos: { | |
type: DataTypes.VIRTUAL, | |
get() { | |
return `${this.nombres} ${this.apellidoPaterno} ${this.apellidoMaterno}`; | |
}, | |
}, | |
tipoDocumento: { | |
allowNull: true, | |
type: DataTypes.STRING, | |
}, | |
numDocumento: { | |
allowNull: true, | |
type: DataTypes.STRING, | |
}, | |
fechaNacimiento: { | |
allowNull: true, | |
type: DataTypes.DATEONLY, | |
}, | |
email: { | |
allowNull: true, | |
type: DataTypes.STRING, | |
}, | |
celular: { | |
allowNull: true, | |
type: DataTypes.STRING, | |
}, | |
numEmergencia: { | |
allowNull: true, | |
type: DataTypes.INTEGER, | |
}, | |
direccion: { | |
allowNull: true, | |
type: DataTypes.STRING, | |
}, | |
carnetExtranjeria: { | |
allowNull: true, | |
type: DataTypes.INTEGER, | |
}, | |
estado: { | |
allowNull: false, | |
type: DataTypes.INTEGER, | |
defaultValue: 1, // activo | |
}, | |
}, { | |
timestamps: true, | |
paranoid: true, | |
version: true, | |
freezeTableName: true, | |
}); | |
Colaborador.associate = function (models) { | |
Colaborador.belongsTo(models.Usuario, { | |
as: 'Usuario', | |
foreignKey: 'usuarioId', | |
targetKey: 'id', | |
}); | |
Colaborador.hasOne(models.Tutor, { | |
as: 'Tutor', | |
foreignKey: 'id', | |
sourceKey: 'id', | |
}); | |
}; | |
return Colaborador; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and try this
module.exports = (sequelize, DataTypes) => { const Colaborador = sequelize.define('Colaborador', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: DataTypes.INTEGER, }, usuarioId: { allowNull: false, type: DataTypes.INTEGER, }, nombres: { allowNull: false, type: DataTypes.STRING, }, apellidoPaterno: { allowNull: false, type: DataTypes.STRING, }, apellidoMaterno: { allowNull: false, type: DataTypes.STRING, }, nombresCompletos: { type: DataTypes.VIRTUAL, get() { return
${this.nombres} ${this.apellidoPaterno} ${this.apellidoMaterno}; }, }, tipoDocumento: { allowNull: true, type: DataTypes.STRING, }, numDocumento: { allowNull: true, type: DataTypes.STRING, }, fechaNacimiento: { allowNull: true, type: DataTypes.DATEONLY, }, email: { allowNull: true, type: DataTypes.STRING, }, celular: { allowNull: true, type: DataTypes.STRING, }, numEmergencia: { allowNull: true, type: DataTypes.INTEGER, }, direccion: { allowNull: true, type: DataTypes.STRING, }, carnetExtranjeria: { allowNull: true, type: DataTypes.INTEGER, }, estado: { allowNull: false, type: DataTypes.INTEGER, defaultValue: 1, // activo }, }, { timestamps: true, paranoid: true, version: true, freezeTableName: true, }); Colaborador.associate = function (models) { Colaborador.belongsTo(models.Usuario); Colaborador.hasOne(models.Tutor); }; return Colaborador; };