You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.
Checklist before submitting:
I've searched for an existing issue.
I've asked my question on Gitter and have not received a satisfactory answer.
I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
The feature I'm asking for is compliant with the JSON:API spec.
Just occured to me while updating from 0.9 to 0.10. Is there any chance that it will be fixed anytime soon?
Monkey-patched this and #1305 like this, but I haven't dived into JR internals too much to evaluate the risks of such patches:
def self._polymorphic_types
@poly_hash ||= {}.tap do |hash|
ActiveRecord::Base.descendants do |klass|
next unless Module === klass
klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection|
(hash[reflection.options[:as]] ||= []) << klass.name.underscore
end
end
end
@poly_hash[_polymorphic_name.to_sym]
end
def _replace_polymorphic_to_one_link(relationship_type, key_value, key_type, _options)
relationship = self.class._relationships[relationship_type.to_sym]
send("#{relationship.foreign_key}=", type: key_type.to_s.classify, id: key_value)
@save_needed = true
:completed
end
This issue is a (choose one):
Checklist before submitting:
Description
Find the complete gist here: https://gist.github.com/ArneZsng/9a5542376d359755f62bbea5f16fb757 or below.
When creating a polymorphic relationship, the type is not properly converted anymore to a class name. This originally was the case in https://github.com/cerebris/jsonapi-resources/pull/288/files#diff-e6cf31c573bd5f2277b1f16812943df4R202 but was since removed with bdcbf61#diff-e6cf31c573bd5f2277b1f16812943df4L324
Instead of straight accepting the incoming type string, it should first be converted to a class name.
A fix would be to change
_replace_polymorphic_to_one_link
in https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/resource.rb to this:Bug Report
Output
The text was updated successfully, but these errors were encountered: