weather_in.js 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { DataTypes, Model } from "sequelize";
import User from "./user";

export class Weather_In extends Model {
  static init(sequelize) {
    return super.init(
      {
        host: {
          type: DataTypes.STRING(320),
          primaryKey: true,
          references: {
            model: User,
            key: "email",
          },
        },
        collected_at: {
          type: DataTypes.DATE,
          primaryKey: true,
        },
        temp: {
          type: DataTypes.FLOAT,
          defaultValue: 0,
        },
        humi: {
          type: DataTypes.FLOAT,
          defaultValue: 0,
        },
        lights: {
          type: DataTypes.FLOAT,
          defaultValue: 0,
        },
      },
      {
        sequelize,
        timestamps: false,
        paranoid: false,
      }
    );
  }

  static associate(db) {
42
    // weather_in 모델이 참조하는 테이블에 대한 외래키 설정.
43
    db.Weather_In.belongsTo(db.User, {
44
45
46
47
48
49
50
      foreignKey: "host",
      targetKey: "email",
    });
  }
}

export default Weather_In;