rentease-backend/models/Apartment.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-03-02 12:36:41 +00:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Region = require('./Region');
const Apartment = sequelize.define('Apartment', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
2026-03-05 15:26:13 +00:00
autoIncrement: true,
comment: '公寓ID'
2026-03-02 12:36:41 +00:00
},
regionId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Region,
key: 'id'
2026-03-05 15:26:13 +00:00
},
comment: '所属区域ID'
2026-03-02 12:36:41 +00:00
},
name: {
type: DataTypes.STRING(50),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '公寓名称'
2026-03-02 12:36:41 +00:00
},
address: {
type: DataTypes.STRING(255),
2026-03-05 15:26:13 +00:00
allowNull: true,
comment: '公寓地址'
2026-03-02 12:36:41 +00:00
},
createTime: {
type: DataTypes.DATE,
2026-03-05 15:26:13 +00:00
defaultValue: DataTypes.NOW,
comment: '创建时间'
2026-03-03 15:36:48 +00:00
},
updateTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
2026-03-05 15:26:13 +00:00
onUpdate: DataTypes.NOW,
comment: '更新时间'
2026-03-03 15:36:48 +00:00
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
2026-03-05 15:26:13 +00:00
defaultValue: 0,
comment: '删除状态0未删除1已删除'
2026-03-02 12:36:41 +00:00
}
}, {
tableName: 'apartments',
timestamps: false
});
// 建立关联
Apartment.belongsTo(Region, { foreignKey: 'regionId' });
Region.hasMany(Apartment, { foreignKey: 'regionId' });
module.exports = Apartment;