Skip to content

WIP - Allow custom scopes.#899

Open
nickurban wants to merge 5 commits intoJSONAPI-Resources:masterfrom
salido:nested_resources
Open

WIP - Allow custom scopes.#899
nickurban wants to merge 5 commits intoJSONAPI-Resources:masterfrom
salido:nested_resources

Conversation

@nickurban
Copy link
Copy Markdown

@nickurban nickurban commented Nov 10, 2016

Supports custom scopes, for example to make nested resources work.

  1. Adds an extension point class method named custom_route_scopes to JSONAPI::Resource, which allows overriding the scopes used to locate the path helper.
  2. If context[:path_parameter] is specified in the controller (via override of context method), this will pass the parameters into the path helper to specify the parent id path segments.

Given routes like this:

jsonapi_resouces :parents do
  jsonapi_relationships
  jsonapi_resources :children
end

Override context in the ChildrenController:

    def context
      { 
        parent_id: params[:parent_id],
        path_parameters: [ params[:parent_id] ],
      }
    end

And a custom ChildProcessor, that e.g. searches using the parent_id.

def load_parent
    parent_id = params[:context].try(:[], :parent_id)
    # TODO: <load the parent resource>
end

and override the show, create_resource etc. methods to call load_parent and work from there.

@nickurban nickurban changed the title WIP - Nested resources working WIP - Supported Nested Resources Nov 10, 2016
@nickurban nickurban changed the title WIP - Supported Nested Resources WIP - Support Nested Resources Nov 10, 2016
@nickurban nickurban changed the title WIP - Support Nested Resources WIP - Allow custom scopes. Nov 10, 2016
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.

1 participant