-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.js
More file actions
40 lines (35 loc) · 811 Bytes
/
Copy pathmodels.js
File metadata and controls
40 lines (35 loc) · 811 Bytes
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
const Sequelize = require('sequelize')
const db = new Sequelize('postgres://localhost:5432/plantr')
const Gardener = db.define('gardener', {
name: {
type: Sequelize.STRING,
},
age: {
type: Sequelize.INTEGER,
}
})
const Plot = db.define('plot', {
size: {
type: Sequelize.INTEGER,
},
shaded: {
type: Sequelize.BOOLEAN,
}
})
const Vegetable = db.define('vegetable', {
name: {
type: Sequelize.STRING,
},
color: {
type: Sequelize.STRING,
},
planted_on: {
type: Sequelize.DATE,
}
})
Plot.belongsTo(Gardener)
Gardener.hasOne(Plot)
Vegetable.belongsToMany(Plot, {through: 'vegetable_plot'})
Plot.belongsToMany(Vegetable, {through: 'vegetable_plot'})
Gardener.belongsTo(Vegetable, {as: 'favorite_vegetable'})
module.exports = {db, Vegetable, Gardener, Plot}