Skip to content
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

fields didn't work well with filter #8649

Closed
markstock7 opened this issue Jul 2, 2017 · 3 comments
Closed

fields didn't work well with filter #8649

markstock7 opened this issue Jul 2, 2017 · 3 comments

Comments

@markstock7
Copy link

window.ghost.url.api('posts', { fields: 'title, slug', filter: tags:foo })

I try to find all the posts which tags = foo, But I don't need server to return all the fields, So i points it out all the fields i need.

but I get error like this : Column 'slug' in field list is ambiguous

is there a way to point out which table's column i need?

@PaszaVonPomiot
Copy link

@markstock7 could you provide list of steps on how to reproduce the error as I would like to test it myself. Also please describe your stack and ghost version.

@markstock7
Copy link
Author

I am using ghost cli to create a ghost server.
And I am using Ghost Restful Api to get posts from my ghost server. as mentioned above,i provided the fileds I want ,and filter.

Request Url like this: ghost/api/v0.1/posts/?fields=title%2C%20slug&filter=tags%3Afoo

and error like this :
select title, slug, id, published_at, author_id from posts left outer join posts_tags on posts_tags.post_id = posts.id left outer join tags on posts_tags.tag_id = tags.id where (posts.status = 'published' and posts.page = false) and (tags.slug = 'foo') group by posts.id order by CASE WHEN posts.status = 'scheduled' THEN 1 WHEN posts.status = 'draft' THEN 2 ELSE 3 END ASC,posts.published_at DESC,posts.updated_at DESC,posts.id DESC limit 15 - ER_NON_UNIQ_ERROR: Column 'slug' in field list is ambiguous

so i think, because the slug is both exist in posts table and tags table, so it is ambiguous.

it change the sql like this, then i will work.

select posts.title, posts.slug, posts.id, published_at, author_id from posts left outer join posts_tags on posts_tags.post_id = posts.id left outer join tags on posts_tags.tag_id = tags.id where (posts.status = 'published' and posts.page = false) and (tags.slug = 'foo') group by posts.id order by CASE WHEN posts.status = 'scheduled' THEN 1 WHEN posts.status = 'draft' THEN 2 ELSE 3 END ASC,posts.published_at DESC,posts.updated_at DESC,posts.id DESC limit 15

@kevinansfield
Copy link
Contributor

This is a known issue, for now the workaround is to avoid using fields if you are filtering on a relationship.

There are a number of issues referencing the problem, notably #5604 and #5615 but they are currently marked later as the proper solution is rather involved and will likely require a deep refactor/rewrite of GQL (there are also related issues open there https://github.com/TryGhost/GQL/issues)

Closing for now as this issue is duplicated in a number of places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants