From 52a97957e14cd56a44f473af5129b1b58ca7893a Mon Sep 17 00:00:00 2001 From: Fabien 'egg' O'Carroll Date: Tue, 1 Jun 2021 11:00:28 +0100 Subject: [PATCH] Added monthly & yearly price relation to Product refs https://github.com/TryGhost/Team/issues/710 This allows us to fetch the default monthly and yearly price models for a product model, which is important since we no longer want to expose the entire list of prices, but just the designated monthly & yearly prices. --- core/server/models/product.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/server/models/product.js b/core/server/models/product.js index 68cab87f44..84639e72e6 100644 --- a/core/server/models/product.js +++ b/core/server/models/product.js @@ -25,6 +25,14 @@ const Product = ghostBookshelf.Model.extend({ } }, + monthlyPrice() { + return this.belongsTo('StripePrice', 'monthly_price_id', 'id'); + }, + + yearlyPrice() { + return this.belongsTo('StripePrice', 'yearly_price_id', 'id'); + }, + stripeProducts() { return this.hasMany('StripeProduct', 'product_id', 'id'); },