Skip to content
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

jsonapi_resource should use relationship.class_name instead of relationship_name #1118

Open
cs3b opened this issue Sep 22, 2017 · 0 comments

Comments

@cs3b
Copy link

cs3b commented Sep 22, 2017

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

cs3b added a commit to cs3b/jsonapi-resources that referenced this issue Sep 22, 2017
allow to pass controller option when defining has_many relation

e.g.
```` ruby
  has_many :kudos_given, class_name: 'Mm::Kudo', controller: 'mm/kudos'
````
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

No branches or pull requests

1 participant