mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Updated post model to attach products relation
refs https://github.com/TryGhost/Team/issues/1071 - attaches products relation for post/pages to include tiers with access when applicable
This commit is contained in:
parent
7ab4c44475
commit
bc5c00ba05
1 changed files with 14 additions and 2 deletions
|
@ -69,11 +69,12 @@ Post = ghostBookshelf.Model.extend({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
relationships: ['tags', 'authors', 'mobiledoc_revisions', 'posts_meta'],
|
relationships: ['tags', 'authors', 'mobiledoc_revisions', 'posts_meta', 'tiers'],
|
||||||
|
|
||||||
// NOTE: look up object, not super nice, but was easy to implement
|
// NOTE: look up object, not super nice, but was easy to implement
|
||||||
relationshipBelongsTo: {
|
relationshipBelongsTo: {
|
||||||
tags: 'tags',
|
tags: 'tags',
|
||||||
|
tiers: 'products',
|
||||||
authors: 'users',
|
authors: 'users',
|
||||||
posts_meta: 'posts_meta'
|
posts_meta: 'posts_meta'
|
||||||
},
|
},
|
||||||
|
@ -89,6 +90,17 @@ Post = ghostBookshelf.Model.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
tiers() {
|
||||||
|
return this.belongsToMany('Product', 'posts_products', 'post_id', 'product_id')
|
||||||
|
.withPivot('sort_order')
|
||||||
|
.query('orderBy', 'sort_order', 'ASC')
|
||||||
|
.query((qb) => {
|
||||||
|
// avoids bookshelf adding a `DISTINCT` to the query
|
||||||
|
// we know the result set will already be unique and DISTINCT hurts query performance
|
||||||
|
qb.columns('products.*');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
parse() {
|
parse() {
|
||||||
const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
|
const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
|
||||||
|
|
||||||
|
@ -171,7 +183,7 @@ Post = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
// transform visibility NQL queries to special-case values where necessary
|
// transform visibility NQL queries to special-case values where necessary
|
||||||
// ensures checks against special-case values such as `{{#has visibility="paid"}}` continue working
|
// ensures checks against special-case values such as `{{#has visibility="paid"}}` continue working
|
||||||
if (attrs.visibility && !['public', 'members', 'paid'].includes(attrs.visibility)) {
|
if (attrs.visibility && !['public', 'members', 'paid', 'tiers'].includes(attrs.visibility)) {
|
||||||
if (attrs.visibility === 'status:-free') {
|
if (attrs.visibility === 'status:-free') {
|
||||||
attrs.visibility = 'paid';
|
attrs.visibility = 'paid';
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue