diff options
| author | Adam Soltys <[email protected]> | 2020-09-27 13:25:59 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-09-27 13:25:59 -0700 |
| commit | 8d42a328880dae07960c56a81649583aab0e71f3 (patch) | |
| tree | 2fcb671868c742c420c1c2bbb5f0c2587d248a14 /db/index.js | |
| parent | 4849c6ac324df67d2f5fc20ed4a958fe9a2bfa1f (diff) | |
| download | coinos-server-8d42a328880dae07960c56a81649583aab0e71f3.tar.gz coinos-server-8d42a328880dae07960c56a81649583aab0e71f3.zip | |
use account foreign keys in proposals table
Diffstat (limited to 'db/index.js')
| -rw-r--r-- | db/index.js | 38 |
1 files changed, 26 insertions, 12 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; |
