mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #5479 from ErisDS/author-relation
Use 'author' for relation instead of 'author_id'
This commit is contained in:
commit
aa333363fe
3 changed files with 4 additions and 11 deletions
|
@ -13,15 +13,8 @@ var Promise = require('bluebird'),
|
|||
|
||||
// ## Helpers
|
||||
function prepareInclude(include) {
|
||||
var index;
|
||||
|
||||
include = include || '';
|
||||
include = _.intersection(include.split(','), allowedIncludes);
|
||||
index = include.indexOf('author');
|
||||
|
||||
if (index !== -1) {
|
||||
include[index] = 'author_id';
|
||||
}
|
||||
|
||||
return include;
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ Post = ghostBookshelf.Model.extend({
|
|||
},
|
||||
|
||||
// Relations
|
||||
author_id: function authorId() {
|
||||
author: function author() {
|
||||
return this.belongsTo('User', 'author_id');
|
||||
},
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ describe('Post Model', function () {
|
|||
});
|
||||
|
||||
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) {
|
||||
should.exist(results);
|
||||
results.length.should.be.above(0);
|
||||
|
@ -99,7 +99,7 @@ describe('Post Model', function () {
|
|||
});
|
||||
|
||||
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) {
|
||||
should.exist(results);
|
||||
|
||||
|
@ -268,7 +268,7 @@ describe('Post Model', function () {
|
|||
it('can findOne, returning all related data', function (done) {
|
||||
var firstPost;
|
||||
// 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) {
|
||||
should.exist(result);
|
||||
firstPost = result.toJSON();
|
||||
|
|
Loading…
Reference in a new issue