Skip to content

#299 optional get relationship from dataset #305

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

Merged

Conversation

senid231
Copy link
Member

@senid231 senid231 commented Oct 3, 2018

related to #299

simple example

class Employee < JsonApiClient::Resource
  self.search_included_in_result_set = true
  has_one :chief, klass: 'Employee'
end

stub_request(:get, '/employees?include=chief') do
{ data: [
    {
        id: '1', 
        type: 'employees', 
        attributes: {  name: 'John' },
        relationships: {
            chief: {
                data: null
            }
        }
    },
    {
        id: '2', 
        type: 'employees', 
        attributes: {  name: 'Bob' },
        relationships: {
            chief: {
                data: { id: '1', type: 'employees' }
            }
        }
    }
] }.to_json
end
employees = Employee.includes(:chief) # responds with
bob = employees.detect { |e| e.name == 'Bob' }
assert_equal 'John', bob.chief.name

@senid231 senid231 self-assigned this Oct 3, 2018
@senid231 senid231 changed the title WIP #299 optional get relationship from dataset WIP: #299 optional get relationship from dataset Oct 3, 2018
@senid231 senid231 force-pushed the 299-get-included-from-dataset branch from 43a2260 to 0b20783 Compare January 14, 2019 14:20
@senid231 senid231 changed the title WIP: #299 optional get relationship from dataset #299 optional get relationship from dataset Jan 14, 2019
@senid231 senid231 requested a review from gaorlov January 14, 2019 14:30
@senid231 senid231 force-pushed the 299-get-included-from-dataset branch from 0b20783 to e5f82d9 Compare January 15, 2019 11:08
@senid231 senid231 merged commit bd298ab into JsonApiClient:master Jan 23, 2019
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

Successfully merging this pull request may close these issues.

2 participants