Skip to content

Instantly share code, notes, and snippets.

@richmolj
Created February 9, 2017 20:10
Show Gist options
  • Save richmolj/b8f7bf8952641acc3beab07f3afc742c to your computer and use it in GitHub Desktop.
Save richmolj/b8f7bf8952641acc3beab07f3afc742c to your computer and use it in GitHub Desktop.
class ContractsController
jsonapi resource: ContractResource
end
class TransactionsController
jsonapi resource: TransactionResource
end
class ContractResource < JsonapiCompliable::Resource
type :contracts
use_adapter JsonapiCompliable::Adapters::ActiveRecord
has_many :transactions,
foreign_key: :contract_id,
scope: -> { Transaction.all },
resource: TransactionResource
polymorphic_belongs_to :workspace,
group_by: proc { |contract| contract.workspace_type },
groups: {
'SpecialWorkspace' => {
resource: WorkspaceResource
},
'AnotherSpecialWorkspace' => {
resource: WorkspaceResource
|
}
end
class TransactionResource < JsonapiCompliable::Resource
type :transactions
end
allow_sideload :workspace, resource: WorkspaceResource do
scope do |contracts|
BasService.call({ 'Filter' => { 'ContractIDs' => contracts.map(&:id) } })
end
assign do |contracts, transactions|
contracts.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment