From 5877e7d2116328bc9689916d74af11ad1293ed7c Mon Sep 17 00:00:00 2001 From: Alan Richards Date: Tue, 22 Apr 2014 23:46:53 -0700 Subject: [PATCH] Tag API response to use parent rather than parent_id Closes #2607 - added toJSON method to tag model - parent_id attribute is replaced by parent - integration tests will expect parent as an attribute --- core/server/models/tag.js | 9 +++++++++ core/test/utils/api.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/server/models/tag.js b/core/server/models/tag.js index e2afc27b98..743910b7b5 100644 --- a/core/server/models/tag.js +++ b/core/server/models/tag.js @@ -27,6 +27,15 @@ Tag = ghostBookshelf.Model.extend({ posts: function () { return this.belongsToMany(Posts); + }, + + toJSON: function (options) { + var attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options); + + attrs.parent = attrs.parent || attrs.parent_id; + delete attrs.parent_id; + + return attrs; } }); diff --git a/core/test/utils/api.js b/core/test/utils/api.js index 817bb8b126..0e0831a325 100644 --- a/core/test/utils/api.js +++ b/core/test/utils/api.js @@ -14,7 +14,7 @@ var _ = require('lodash'), settings: ['databaseVersion', 'dbHash', 'title', 'description', 'email', 'logo', 'cover', 'defaultLang', "permalinks", 'postsPerPage', 'forceI18n', 'activeTheme', 'activeApps', 'installedApps', 'availableThemes', 'availableApps', 'nextUpdateCheck', 'displayUpdateNotification'], - tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent_id', + tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent', 'meta_title', 'meta_description', 'created_at', 'created_by', 'updated_at', 'updated_by'], user: ['id', 'uuid', 'name', 'slug', 'email', 'image', 'cover', 'bio', 'website', 'location', 'accessibility', 'status', 'language', 'meta_title', 'meta_description',