Ghost/core/server/models/posts-meta.js
Naz 755a3a320e Added email_only column to posts_meta table
closes https://github.com/TryGhost/Team/issues/893

- We need a place to store email-only flag and posts_meta is the best place for it
2021-08-05 19:44:35 +12:00

43 lines
988 B
JavaScript

const ghostBookshelf = require('./base');
const urlUtils = require('../../shared/url-utils');
const PostsMeta = ghostBookshelf.Model.extend({
tableName: 'posts_meta',
defaults: function defaults() {
return {
email_only: false
};
},
formatOnWrite(attrs) {
['og_image', 'twitter_image'].forEach((attr) => {
if (attrs[attr]) {
attrs[attr] = urlUtils.toTransformReady(attrs[attr]);
}
});
return attrs;
},
parse() {
const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
['og_image', 'twitter_image'].forEach((attr) => {
if (attrs[attr]) {
attrs[attr] = urlUtils.transformReadyToAbsolute(attrs[attr]);
}
});
return attrs;
}
}, {
post() {
return this.belongsTo('Post');
}
});
module.exports = {
PostsMeta: ghostBookshelf.model('PostsMeta', PostsMeta)
};