diff --git a/ghost/admin/mirage/factories/tag.js b/ghost/admin/mirage/factories/tag.js index 66db206988..9ea30ee572 100644 --- a/ghost/admin/mirage/factories/tag.js +++ b/ghost/admin/mirage/factories/tag.js @@ -14,8 +14,7 @@ export default Factory.extend({ updatedAt: '2015-10-19T16:25:07.756Z', updatedBy: 1, count() { - return { - posts: 1 - }; + // this gets updated automatically by the tag serializer + return {posts: 0}; } }); diff --git a/ghost/admin/mirage/serializers/tag.js b/ghost/admin/mirage/serializers/tag.js new file mode 100644 index 0000000000..6906521de0 --- /dev/null +++ b/ghost/admin/mirage/serializers/tag.js @@ -0,0 +1,18 @@ +import BaseSerializer from './application'; + +export default BaseSerializer.extend({ + // make the tag.count.posts value dynamic + serialize(tagModelOrCollection, request) { + let updatePostCount = (tag) => { + tag.update('count', {posts: tag.postIds.length}); + }; + + if (this.isModel(tagModelOrCollection)) { + updatePostCount(tagModelOrCollection); + } else { + tagModelOrCollection.models.forEach(updatePostCount); + } + + return BaseSerializer.prototype.serialize.call(this, tagModelOrCollection, request); + } +});