Skip to content

provide fields parameter from request to operation#711

Merged
lgebhardt merged 2 commits intoJSONAPI-Resources:masterfrom
senid231:provide_fields_to_operation
May 24, 2016
Merged

provide fields parameter from request to operation#711
lgebhardt merged 2 commits intoJSONAPI-Resources:masterfrom
senid231:provide_fields_to_operation

Conversation

@senid231
Copy link
Copy Markdown
Contributor

it allows for example to do something like:

class CatResource < JSONAPI::Resource
  attributes :name, :breed

  filters :name

  def self.records(options = {})
    fields = options.fetch(:fields, {})[:cats]
    coll = super
    fields.nil? ? coll : coll.select(fields.join(','))
  end

end
class ExtendedMetaOperationsProcessor < ActiveRecordOperationsProcessor

  after_find_operation do
    @operation_meta[:fields] = @operation.fields
  end

end

… to resource_klass.find or resource_klass.find_by_key (when fetching data)
@senid231
Copy link
Copy Markdown
Contributor Author

any updates about this?

@lgebhardt
Copy link
Copy Markdown
Contributor

@senid231 Sorry, merging #694 created a few conflicts with this. Could you rework this to work with the new changes?

Conflicts:
	lib/jsonapi/operation.rb
@senid231
Copy link
Copy Markdown
Contributor Author

done

@lgebhardt lgebhardt merged commit 09b5f2c into JSONAPI-Resources:master May 24, 2016
@lgebhardt
Copy link
Copy Markdown
Contributor

@senid231 Thanks!

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