diff --git a/core/server/models/product.js b/core/server/models/product.js index 3fdcb42fcc..68cab87f44 100644 --- a/core/server/models/product.js +++ b/core/server/models/product.js @@ -25,7 +25,22 @@ const Product = ghostBookshelf.Model.extend({ } }, - members: function members() { + stripeProducts() { + return this.hasMany('StripeProduct', 'product_id', 'id'); + }, + + stripePrices() { + return this.belongsToMany( + 'StripePrice', + 'stripe_products', + 'product_id', + 'stripe_product_id', + 'id', + 'stripe_product_id' + ); + }, + + members() { return this.belongsToMany('Member', 'members_products', 'product_id', 'member_id'); } }); diff --git a/core/server/models/stripe-product.js b/core/server/models/stripe-product.js index aed7629a10..c62a8abf63 100644 --- a/core/server/models/stripe-product.js +++ b/core/server/models/stripe-product.js @@ -5,6 +5,10 @@ const StripeProduct = ghostBookshelf.Model.extend({ product() { return this.belongsTo('Product', 'product_id', 'id'); + }, + + stripePrices() { + return this.hasMany('StripePrice', 'stripe_product_id', 'stripe_product_id'); } }, {