Skip to content

jsonapi_resource should use relationship.class_name instead of relationship_name #1118

@cs3b

Description

@cs3b

We have models Contractor and Mm::Kudo and corresponding resources.

class ContractorResource < JSONAPI::Resource
  model_name 'Coworker'
  attributes :name, :uid, :avatar_url

  has_many :kudos_given, class_name: 'Mm::Kudo'
end

class Mm::KudoResource < JSONAPI::Resource
  model_name 'Mm::Kudo'
  attributes :value, :tags, :comment

  has_one :giver, class_name: 'Contractor'
end

And generate route for kudos-received relation points to kudos#get_related_resources controller instead of mm/kudos#get_related_resources (btw.: includes work fine)

There two options:

  1. leave the default behaviour as it is and allow to overwrite controller at relationship level

e.g.: for the given example

  has_many :kudos_given, class_name: 'Mm::Kudo', controller: 'mm/kudos'

and pass the relationship params to the jsonapi_related_resources

  1. use model_name to generate path for default controller (and still allow to overwrite controller at the has_many definition

Which option should we pick and adopt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions