-
Notifications
You must be signed in to change notification settings - Fork 532
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
Polymorphic relations problem: undefined method for nil:NilClass #1305
Comments
Oh wow, this is great. I just commented on where this behavior was imho introduced, in #1045 (comment) but you actually wrote a test case! I think is similar to
historically related |
Are there any updates on this issue? |
@rafahuaman For now I've taken @bf4's #1349 pr and made a few changes in a test branch, https://github.com/cerebris/jsonapi-resources/compare/bf4_fix_polymorphic_relations_lookup?expand=1, including a workaround that requires additional relationships on the model to help resolve each supported polymorphic type. Like
I'm going to work on finding a solution that does not need this type of hack. I believe the hack could work with the latest releases if you also specify the polymorphic_types on the resource relationship:
|
Oh, that's good news. I never got to te heart of it
…On Wed, Mar 10, 2021, 5:09 PM Larry Gebhardt ***@***.***> wrote:
@rafahuaman <https://github.com/rafahuaman> For now I've taken @bf4
<https://github.com/bf4>'s #1349
<#1349> pr and made a
few changes in a test branch,
https://github.com/cerebris/jsonapi-resources/tree/bf4_fix_polymorphic_relations_lookup,
including a work around that requires additional relationships on the model
to help resolve each supported polymorphic type. Like
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1305 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABC4QQXR2HD2D3CWJM362DTC7UYVANCNFSM4KMBNQKQ>
.
|
@lgebhardt Thank you for the reply |
Hello, what is the status on this issue? |
i needed a fix asap and nothing worked except for this
|
I get this because there could be singleton classes in the ObjectSpace.each_object
.select { Class === _1 }
.select { _1 < ActiveRecord::Base }
.select(&:name) |
Looks like |
This issue is a (choose one):
Checklist before submitting:
Description
I seem to have bumped into a problem with polymorphic relations I'm unable to solve. Here's a description and a standalone bug report describing it. I'm on JR 0.10.2, Rails 6.0.2.1 and Ruby 2.6.5.
The model in question is composed of three ActiveRecord models: ContactMedium, Individuals and Organizations and the corresponding JR resources. The latter may have many contact media as party and one contact medium can belong to either kind of party.
The problem comes up when trying to get the individual or organisation as party via the contact media like this: GET /contact-media/1/party
The logic works on ActiveRecord level but not in the JR level.
Using the relationship results in the following error in the included example case:
The error is similar in the actual app but with a mild difference (that also included in the included pastebin link):
I'm suspecting this behaviour to be a bug. If I'm doing something wrong instead, please let me know. Workaround suggestions also welcome!
Bug reports:
Partial report in pastebin
https://pastebin.com/V0CfEs3F
Standalone bug report using the template
The text was updated successfully, but these errors were encountered: