Ghost/core/server/models/posts-meta.js
Kevin Ansfield dc9a22d4de
Updated post model url transforms for posts/posts_meta split (#11223)
no issue

- `og_image` and `twitter_image` fields are now located in a separate model so the transform functionality for those fields needed to move accordingly
2019-10-09 13:38:08 +01:00

39 lines
1.1 KiB
JavaScript

const ghostBookshelf = require('./base');
const urlUtils = require('../lib/url-utils');
const PostsMeta = ghostBookshelf.Model.extend({
tableName: 'posts_meta',
onSaving: function onSaving() {
const urlTransformMap = {
og_image: 'absoluteToRelative',
twitter_image: 'absoluteToRelative'
};
Object.entries(urlTransformMap).forEach(([attr, transform]) => {
let method = transform;
let methodOptions = {};
if (typeof transform === 'object') {
method = transform.method;
methodOptions = transform.options || {};
}
if (this.hasChanged(attr) && this.get(attr)) {
const transformedValue = urlUtils[method](this.get(attr), methodOptions);
this.set(attr, transformedValue);
}
});
ghostBookshelf.Model.prototype.onSaving.apply(this, arguments);
}
}, {
post() {
return this.belongsTo('Post');
}
});
module.exports = {
PostsMeta: ghostBookshelf.model('PostsMeta', PostsMeta)
};