aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/index.js28
1 files changed, 23 insertions, 5 deletions
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;