New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"url" field is undefined when restricting returned fields via the API #7089
Conversation
Please review. Response returns |
The author/author_id aspect is a slightly blurry boundary because it is a related object. Posts have a Ideally at this point, you would be able to say |
I have tested this out with the reproduction steps listed in this comment and am no longer able to reproduce either bug 😉 |
Added a test case for this fix. Good for review. |
i was able to reproduce with postman. will review |
if (_.isArray(options.columns)) { | ||
requestedColumns = _.clone(options.columns); | ||
if (_.includes(options.columns, 'url') || _.includes(options.columns, 'author')) { | ||
options.columns.push('id', 'published_at', 'slug', 'author_id'); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Based on @kirrg001 suggestion above, implemented a more generic solution. Base class for models defines
Finally, the response from |
@@ -355,14 +362,21 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ | |||
} | |||
|
|||
return itemCollection.fetchPage(options).then(function formatResponse(response) { | |||
var data = {}; | |||
options.columns = allColumns; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
The failing lint build was a random travis error - this is green now! |
- "url" and "author" fields depend on {id, published_at, slug, author_id} to construct post url. - implemented a generic solution by defining defaultColumnsToFetch() in base class for models. - findPage() calls defaultColumnsToFetch() before loading models - results are transformed by filtering out additional properties to return just the requested fields - Added a test case to check for url and author fields - Renamed allColumns as requestedColumns and used _.map instead of Promise.map
As per the suggestions above, renamed |
…ost#7089) closes TryGhost#6625 - "url" and "author" fields depend on {id, published_at, slug, author_id} to construct post url. - implemented a generic solution by defining defaultColumnsToFetch() in base class for models. - findPage() calls defaultColumnsToFetch() before loading models - results are transformed by filtering out additional properties to return just the requested fields - Added a test case to check for url and author fields - Renamed allColumns as requestedColumns and used _.map instead of Promise.map
…ost#7089) closes TryGhost#6625 - "url" and "author" fields depend on {id, published_at, slug, author_id} to construct post url. - implemented a generic solution by defining defaultColumnsToFetch() in base class for models. - findPage() calls defaultColumnsToFetch() before loading models - results are transformed by filtering out additional properties to return just the requested fields - Added a test case to check for url and author fields - Renamed allColumns as requestedColumns and used _.map instead of Promise.map
Closes #6625
GET /posts
query with?field=url
as query string returns "undefined" as url value. Theurl
property is constructed from id, published_dt, and slug. Post instances are loaded with attributes given infields
parameter. If thefields
parameter doesn't containid
,published_dt
, andslug
, URL can't be constructed and undefined is returned.Fix was to load the 3 required properties when
field
parameter containsurl
. Response is sent after filtering out any properties that were not requested.