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

Unable to select specific fields from a related model #114

Closed
jryd opened this issue Oct 17, 2018 · 2 comments
Closed

Unable to select specific fields from a related model #114

jryd opened this issue Oct 17, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@jryd
Copy link

jryd commented Oct 17, 2018

I have a model called Recipe which links to a model called BjcpStyle.

The relationship looks like this:

public function bjcpStyle()
    {
        return $this->belongsTo(BjcpStyle::class, 'bjcp_style_id', 'sub_category_id');
    }

I only want to select sub_category_id and name from the BjcpStyle model.

So I drummed up a query like this; /recipes?include=bjcp-style&fields[bjcp-style]=sub_category_id,name

However this returns all fields for the BjcpStyle model.

Other URLs I have tried:

  • /recipes?include=bjcp-style&fields[bjcp_styles]=sub_category_id,name (the table name itself)
  • /recipes?include=bjcp-style&fields[bjcpStyle]=sub_category_id,name (the name of the actual relationship)

However neither of these work.

I did some very basic debugging by chucking a bunch of dump() statements in the QueryBuilder file to see what was coming through and it looks like it is picking up that I have specified bjcp-style as a field in the request, but when parsing the table name and fields, I do not see any processing for this.

Am I doing something wrong in the request above, or is there an issue here?

@AlexVanderbist
Copy link
Member

This might be the same issue as #118. A fix for that was tagged a couple of minutes ago in 1.11.2. Can you check if the issue is still there in that version? Thanks.

@AlexVanderbist AlexVanderbist added the bug Something isn't working label Oct 30, 2018
@jryd
Copy link
Author

jryd commented Oct 30, 2018

@AlexVanderbist yep, this solves my issue!

@jryd jryd closed this as completed Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants