0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Merge pull request #5479 from ErisDS/author-relation

Use 'author' for relation instead of 'author_id'
This commit is contained in:
Jason Williams 2015-06-24 09:01:20 -05:00
commit aa333363fe
3 changed files with 4 additions and 11 deletions

View file

@ -13,15 +13,8 @@ var Promise = require('bluebird'),
// ## Helpers // ## Helpers
function prepareInclude(include) { function prepareInclude(include) {
var index;
include = include || ''; include = include || '';
include = _.intersection(include.split(','), allowedIncludes); include = _.intersection(include.split(','), allowedIncludes);
index = include.indexOf('author');
if (index !== -1) {
include[index] = 'author_id';
}
return include; return include;
} }

View file

@ -239,7 +239,7 @@ Post = ghostBookshelf.Model.extend({
}, },
// Relations // Relations
author_id: function authorId() { author: function author() {
return this.belongsTo('User', 'author_id'); return this.belongsTo('User', 'author_id');
}, },

View file

@ -66,7 +66,7 @@ describe('Post Model', function () {
}); });
it('can findAll, returning all related data', function (done) { it('can findAll, returning all related data', function (done) {
PostModel.findAll({include: ['author_id', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) PostModel.findAll({include: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']})
.then(function (results) { .then(function (results) {
should.exist(results); should.exist(results);
results.length.should.be.above(0); results.length.should.be.above(0);
@ -99,7 +99,7 @@ describe('Post Model', function () {
}); });
it('can findPage, returning all related data', function (done) { it('can findPage, returning all related data', function (done) {
PostModel.findPage({include: ['author_id', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) PostModel.findPage({include: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']})
.then(function (results) { .then(function (results) {
should.exist(results); should.exist(results);
@ -268,7 +268,7 @@ describe('Post Model', function () {
it('can findOne, returning all related data', function (done) { it('can findOne, returning all related data', function (done) {
var firstPost; var firstPost;
// TODO: should take author :-/ // TODO: should take author :-/
PostModel.findOne({}, {include: ['author_id', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']}) PostModel.findOne({}, {include: ['author', 'fields', 'tags', 'created_by', 'updated_by', 'published_by']})
.then(function (result) { .then(function (result) {
should.exist(result); should.exist(result);
firstPost = result.toJSON(); firstPost = result.toJSON();