Don't pass helper options to API for next/prev

fixes #5177

- this combined with a change passing options through to toJSON results in a really flukey bug with next/prev
  where the name option from the helper clashes with a name option inside of toJSON
This commit is contained in:
Hannah Wolfe 2015-04-22 19:56:56 +01:00
parent 32125c2f46
commit eb5eca6eda

View File

@ -8,9 +8,10 @@ var api = require('../api'),
Promise = require('bluebird'),
fetch, prevNext;
fetch = function (options) {
return api.posts.read(options).then(function (result) {
fetch = function (apiOptions, options) {
return api.posts.read(apiOptions).then(function (result) {
var related = result.posts[0];
if (related.previous) {
return options.fn(related.previous);
} else if (related.next) {
@ -26,10 +27,14 @@ fetch = function (options) {
prevNext = function (options) {
options = options || {};
options.include = options.name === 'prev_post' ? 'previous' : 'next';
var apiOptions = {
include: options.name === 'prev_post' ? 'previous' : 'next'
};
if (schema.isPost(this)) {
options.slug = this.slug;
return fetch(options);
apiOptions.slug = this.slug;
return fetch(apiOptions, options);
} else {
return Promise.resolve(options.inverse(this));
}