Skip to content

has_one :giver, class_name: '::Contractor' #1120

@cs3b

Description

@cs3b

doesn't look for resources in the main namespace

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

  has_one :giver, class_name: '::Contractor'
end````

I've got error 

```` bash
NameError: JSONAPI: Could not find resource 'mm//contractors'. (Class Mm::::ContractorResource not found)

how should I define that the relation is in the top level namespace?

Activity

added a commit that references this issue on Sep 22, 2017
travisofthenorth

travisofthenorth commented on Jan 18, 2018

@travisofthenorth
Contributor

+1

I'm having the same issue. The only workaround is to add another instance of the ContractorResource, per this example. I.e. you'd have to add:

module Mm
  class ContractorResource < ::ContractorResource
  end
end

This is really unfortunate for pretty clear reasons, e.g. you can have disparate functionality in these two classes. Could a possible solution be to add a resource_name option on relationships similar to the current class_name option?

simonc

simonc commented on Sep 22, 2021

@simonc

Hi there,

Working with the master branch here as we need the serialize_to_hash back. This issue also happens, with class_name not being used.

This seems to come from JoinManager#add_source_relationship which seems to be ignoring the class_name option and thus trying to compute the class name of the resource on its own.

❤️

arcreative

arcreative commented on Dec 30, 2021

@arcreative
Contributor

This appears to be a regression in 0.10.x--I don't have this issue in 0.9.12. After upgrading, I'm forced to specify the class_name on the has_one, which is a non-starter for me because it's being invoked via the parent class, and I can't pass options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @simonc@cs3b@travisofthenorth@arcreative

        Issue actions

          has_one :giver, class_name: '::Contractor' · Issue #1120 · cerebris/jsonapi-resources