hooks como foreignkey

This commit is contained in:
2020-10-01 10:14:38 -05:00
parent 886ec20eaa
commit 0df256dcac
10 changed files with 126 additions and 160 deletions
+7 -18
View File
@@ -13,22 +13,6 @@ CarreraPlantel.init(
autoIncrement: true,
unique: true,
},
idPlantel: {
type: DataTypes.INTEGER,
references: {
model: Plantel,
key: 'idPlantel',
},
allowNull: false,
},
idCarrera: {
type: DataTypes.INTEGER,
references: {
model: Carrera,
key: 'idCarrera',
},
allowNull: false,
},
},
{
sequelize,
@@ -38,7 +22,12 @@ CarreraPlantel.init(
}
)
CarreraPlantel.belongsTo(Carrera, { foreignKey: 'idCarrera' })
CarreraPlantel.belongsTo(Plantel, { foreignKey: 'idPlantel' })
CarreraPlantel.belongsTo(Carrera, {
foreignKey: { type: DataTypes.INTEGER, name: 'idCarrera', allowNull: false },
})
CarreraPlantel.belongsTo(Plantel, {
foreignKey: { type: DataTypes.INTEGER, name: 'idPlantel', allowNull: false },
})
module.exports = CarreraPlantel
+8 -8
View File
@@ -20,14 +20,6 @@ Carrito.init(
type: DataTypes.STRING(1),
allowNull: false,
},
idTipoCarrito: {
type: DataTypes.INTEGER,
references: {
model: TipoCarrito,
key: 'idTipoCarrito',
},
allowNull: false,
},
},
{
sequelize,
@@ -36,4 +28,12 @@ Carrito.init(
}
)
Carrito.belongsTo(TipoCarrito, {
foreignKey: {
name: 'idTipoCarrito',
type: DataTypes.INTEGER,
allowNull: false,
},
})
module.exports = Carrito
+17 -16
View File
@@ -28,24 +28,8 @@ Equipo.init(
activo: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
idCarrito: {
type: DataTypes.INTEGER,
references: {
model: Carrito,
key: 'idCarrito',
},
allowNull: false,
},
idStatus: {
type: DataTypes.INTEGER,
references: {
model: Status,
key: 'idStatus',
},
allowNull: false,
// defaultValue: 1,
},
},
{
sequelize,
@@ -54,4 +38,21 @@ Equipo.init(
}
)
Equipo.belongsTo(Status, {
foreignKey: {
name: 'idStatus',
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
})
Equipo.belongsTo(Carrito, {
foreignKey: {
name: 'idCarrito',
type: DataTypes.INTEGER,
allowNull: false,
},
})
module.exports = Equipo
+9 -8
View File
@@ -19,15 +19,7 @@ Mesa.init(
activo: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
idStatus: {
type: DataTypes.INTEGER,
references: {
model: Status,
key: 'idStatus',
},
allowNull: false,
defaultValue: 1,
},
},
{
@@ -37,4 +29,13 @@ Mesa.init(
}
)
Mesa.belongsTo(Status, {
foreignKey: {
name: 'idStatus',
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
})
module.exports = Mesa
+12 -16
View File
@@ -21,22 +21,6 @@ Multa.init(
type: DataTypes.STRING(100),
allowNull: false,
},
idTipoMulta: {
type: DataTypes.INTEGER,
references: {
model: TipoMulta,
key: 'idTipoMulta',
},
allowNull: false,
},
idPrestamo: {
type: DataTypes.INTEGER,
references: {
model: Prestamo,
key: 'idPrestamo',
},
allowNull: false,
},
},
{
sequelize,
@@ -45,4 +29,16 @@ Multa.init(
}
)
Multa.belongsTo(TipoMulta, {
foreignKey: {
name: 'idTipoMulta',
type: DataTypes.INTEGER,
allowNull: false,
},
})
Multa.belongsTo(Prestamo, {
foreignKey: { name: 'idPrestamo', type: DataTypes.INTEGER, allowNull: false },
})
module.exports = Multa
+8 -8
View File
@@ -20,14 +20,6 @@ Operador.init(
type: DataTypes.STRING(100),
allowNull: false,
},
idTipoOperador: {
type: DataTypes.INTEGER,
references: {
model: TipoOperador,
key: 'idTipoOperador',
},
allowNull: false,
},
},
{
sequelize,
@@ -36,4 +28,12 @@ Operador.init(
}
)
Operador.belongsTo(TipoOperador, {
foreignKey: {
name: 'idTipoOperador',
type: DataTypes.INTEGER,
allowNull: false,
},
})
module.exports = Operador
+36 -55
View File
@@ -28,63 +28,8 @@ Prestamo.init(
activo: {
type: DataTypes.BOOLEAN,
defaultValue: true,
},
idUsuario: {
type: DataTypes.INTEGER,
references: {
model: Usuario,
key: 'idUsuario',
},
allowNull: false,
},
idOperadorEntrega: {
type: DataTypes.INTEGER,
references: {
model: Operador,
key: 'idOperador',
},
allowNull: true,
},
idOperadorRegreso: {
type: DataTypes.INTEGER,
references: {
model: Operador,
key: 'idOperador',
},
allowNull: true,
},
idEquipo: {
type: DataTypes.INTEGER,
references: {
model: Equipo,
key: 'idEquipo',
},
allowNull: true,
},
idHorario: {
type: DataTypes.INTEGER,
references: {
model: Horario,
key: 'idHorario',
},
allowNull: false,
},
idMesa: {
type: DataTypes.INTEGER,
references: {
model: Mesa,
key: 'idMesa',
},
allowNull: true,
},
idSalon: {
type: DataTypes.INTEGER,
references: {
model: Salon,
key: 'idSalon',
},
allowNull: true,
},
},
{
sequelize,
@@ -93,4 +38,40 @@ Prestamo.init(
}
)
Prestamo.belongsTo(Usuario, {
foreignKey: { name: 'idUsuario', type: DataTypes.INTEGER, allowNull: false },
})
Prestamo.belongsTo(Operador, {
foreignKey: {
name: 'idOperadorEntrega',
type: DataTypes.INTEGER,
allowNull: true,
},
})
Prestamo.belongsTo(Operador, {
foreignKey: {
name: 'idOperadorRegreso',
type: DataTypes.INTEGER,
allowNull: true,
},
})
Prestamo.belongsTo(Equipo, {
foreignKey: { name: 'idEquipo', type: DataTypes.INTEGER, allowNull: true },
})
Prestamo.belongsTo(Mesa, {
foreignKey: { name: 'idMesa', type: DataTypes.INTEGER, allowNull: true },
})
Prestamo.belongsTo(Salon, {
foreignKey: { name: 'idSalon', type: DataTypes.INTEGER, allowNull: true },
})
Prestamo.belongsTo(Horario, {
foreignKey: { name: 'idHorario', type: DataTypes.INTEGER, allowNull: false },
})
module.exports = Prestamo
+4 -8
View File
@@ -16,14 +16,6 @@ Reporte.init(
type: DataTypes.STRING(100),
allowNull: false,
},
idPrestamo: {
type: DataTypes.INTEGER,
references: {
model: Prestamo,
key: 'idPrestamo',
},
allowNull: false,
},
},
{
sequelize,
@@ -32,4 +24,8 @@ Reporte.init(
}
)
Reporte.belongsTo(Prestamo, {
foreignKey: { name: 'idPrestamo', type: DataTypes.INTEGER, allowNull: false },
})
module.exports = Reporte
+9 -8
View File
@@ -19,15 +19,7 @@ Salon.init(
activo: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
idStatus: {
type: DataTypes.INTEGER,
references: {
model: Status,
key: 'idStatus',
},
allowNull: false,
defaultValue: 1,
},
},
{
@@ -37,4 +29,13 @@ Salon.init(
}
)
Salon.belongsTo(Status, {
foreignKey: {
name: 'idStatus',
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
})
module.exports = Salon
+16 -15
View File
@@ -47,21 +47,6 @@ Usuario.init(
baneado: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
idCarreraPlantel: {
type: DataTypes.INTEGER,
references: {
model: CarreraPlantel,
key: 'idCarreraPlantel',
},
allowNull: false,
},
idTipoUsuario: {
type: DataTypes.INTEGER,
references: {
model: TipoUsuario,
key: 'idTipoUsuario',
},
allowNull: false,
},
},
@@ -72,4 +57,20 @@ Usuario.init(
}
)
Usuario.belongsTo(TipoUsuario, {
foreignKey: {
name: 'idTipoUsuario',
type: DataTypes.INTEGER,
allowNull: false,
},
})
Usuario.belongsTo(CarreraPlantel, {
foreignKey: {
name: 'idCarreraPlantel',
type: DataTypes.INTEGER,
allowNull: false,
},
})
module.exports = Usuario