From 08ce348c68fc69c54b64388aff32ff7bcf53e8b9 Mon Sep 17 00:00:00 2001 From: Ran Guin Date: Sat, 15 May 2021 21:41:14 -0700 Subject: add fk references for referral model --- db/index.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'db') diff --git a/db/index.js b/db/index.js index 303f61ef..41593069 100644 --- a/db/index.js +++ b/db/index.js @@ -49,7 +49,7 @@ require("./normalized/waiting_list.js"); // require("./normalized/orders.js"); // require("./normalized/invoices.js"); -const { User, Account, Payment, Invoice, Key, Order } = db; +const { User, Account, Payment, Invoice, Key, Order, Referral} = db; // move relationships to specfic models User.hasMany(Account, { @@ -77,10 +77,10 @@ User.hasMany(Payment, { foreignKey: "user_id" }); -User.belongsTo(Account, { - as: "account", - foreignKey: "account_id" -}); +// User.belongsTo(Account, { +// as: "account", +// foreignKey: "account_id" +// }); Invoice.belongsTo(Account, { as: "account", @@ -127,5 +127,23 @@ Order.belongsTo(Account, { foreignKey: "a2_id" }); +User.hasMany(Referral, { + as: "referral_codes", + foreignKey: "sponsor_id" +}); +User.hasMany(Referral, { + as: "sponsors", + foreignKey: "user_id" +}); + +Referral.belongsTo(User, { + as: "sponsor", + foreignKey: "sponsor_id" +}); +Referral.belongsTo(User, { + as: "user", + foreignKey: "user_id" +}); + debug('added model relationships') db.Order = Order; -- cgit v1.2.3