aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/index.js38
-rw-r--r--db/models/proposals.js40
2 files changed, 46 insertions, 32 deletions
diff --git a/db/index.js b/db/index.js
index 6fa225e6..0772bfc7 100644
--- a/db/index.js
+++ b/db/index.js
@@ -16,62 +16,76 @@ require("./models/payments.js");
require("./models/proposals.js");
require("./models/users.js");
-db["User"].hasMany(db["Account"], {
+const { User, Account, Payment, Invoice, Key, Proposal } = db;
+
+User.hasMany(Account, {
as: "accounts",
foreignKey: "user_id"
});
-db["User"].hasMany(db["Invoice"], {
+User.hasMany(Invoice, {
as: "invoices",
foreignKey: "user_id"
});
-db["User"].hasMany(db["Key"], {
+User.hasMany(Key, {
as: "keys",
foreignKey: "user_id"
});
-db["User"].hasMany(db["Payment"], {
+User.hasMany(Payment, {
as: "payments",
foreignKey: "user_id"
});
-db["User"].belongsTo(db["Account"], {
+User.belongsTo(Account, {
as: "account",
foreignKey: "account_id"
});
-db["Invoice"].belongsTo(db["Account"], {
+Invoice.belongsTo(Account, {
as: "account",
foreignKey: "account_id"
});
-db["Account"].belongsTo(db["User"], {
+Account.belongsTo(User, {
as: "user",
foreignKey: "user_id"
});
-db["Invoice"].belongsTo(db["User"], {
+Invoice.belongsTo(User, {
as: "user",
foreignKey: "user_id"
});
-db["Key"].belongsTo(db["User"], {
+Key.belongsTo(User, {
as: "user",
foreignKey: "user_id"
});
-db["Payment"].belongsTo(db["Account"], {
+Payment.belongsTo(Account, {
as: "account",
foreignKey: "account_id"
});
-db["Payment"].belongsTo(db["User"], {
+Payment.belongsTo(User, {
as: "user",
foreignKey: "user_id"
});
-db["Proposal"].belongsTo(db["User"], {
+Proposal.belongsTo(User, {
as: "user",
foreignKey: "user_id"
});
+
+Proposal.belongsTo(Account, {
+ as: "acc1",
+ foreignKey: "a1_id"
+});
+
+Proposal.belongsTo(Account, {
+ as: "acc2",
+ foreignKey: "a2_id"
+});
+
+db.Proposal = Proposal;
diff --git a/db/models/proposals.js b/db/models/proposals.js
index ca3de8eb..44f2f796 100644
--- a/db/models/proposals.js
+++ b/db/models/proposals.js
@@ -1,4 +1,4 @@
-const { DataTypes } = require('sequelize');
+const { DataTypes } = require("sequelize");
const attributes = {
id: {
@@ -10,6 +10,24 @@ const attributes = {
comment: null,
field: "id"
},
+ a1_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "a1_id"
+ },
+ a2_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "a2_id"
+ },
user_id: {
type: DataTypes.INTEGER(11),
allowNull: true,
@@ -46,24 +64,6 @@ const attributes = {
comment: null,
field: "updatedAt"
},
- a1: {
- type: DataTypes.STRING(255),
- allowNull: true,
- defaultValue: null,
- primaryKey: false,
- autoIncrement: false,
- comment: null,
- field: "a1"
- },
- a2: {
- type: DataTypes.STRING(255),
- allowNull: true,
- defaultValue: null,
- primaryKey: false,
- autoIncrement: false,
- comment: null,
- field: "a2"
- },
v1: {
type: DataTypes.DOUBLE,
allowNull: true,
@@ -126,4 +126,4 @@ const options = {
indexes: []
};
-db["Proposal"] = db.define("proposals_model", attributes, options);
+db.Proposal = db.define("proposals_model", attributes, options);