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
Hello! I put all the serializers under the API namespace. My problem was that parent serializer
could not find serializers for the associated array of objects. I added the following patch to my
codebase to temporary fix this issue:
#lib/active_model_serializers/lazy_association_patch.rb# AMS v0.10.7 doesn't respect `namespace` option in the `has_many` association## class API::UserSerializer < ActiveModel::Serializer# has_many :changesets, namespace: API# end## To make AMS take in the account namespace when it finds serializer for collection's objects# has been patched `instantiate_serializer` method in the `ActiveModel::Serializer::LazyAssociation`require'active_model/serializer/lazy_association'classActiveModel::Serializer::LazyAssociationdefinstantiate_serializer(object)serializer_options=association_options.fetch(:parent_serializer_options).except(:serializer)serializer_options[:serializer_context_class]=association_options.fetch(:parent_serializer).classserializer=reflection_options.fetch(:serializer,nil)serializer_options[:serializer]=serializerifserializer# forward namespace to the collection serializerserializer_options[:namespace]=reflection_options[:namespace]ifreflection_options[:namespace]serializer_class.new(object,serializer_options)endend
Then I looked into the test suite for AMS and was able to reproduce this bug with fixtures which are used in the AMS tests
Hello! I put all the serializers under the API namespace. My problem was that parent serializer
could not find serializers for the associated array of objects. I added the following patch to my
codebase to temporary fix this issue:
Then I looked into the test suite for AMS and was able to reproduce this bug with fixtures which are used in the AMS tests
But it should be
ResourceNamespace::CommentSerializer
I've added a failing test which tests serializing of not namespaced objects using namespaced serializers and the fix above seems to made it green
I plan to open a PR related to this bug.
--
It would be cool to omit
namespace: API
every time I define associations in a namespaced serializerThe text was updated successfully, but these errors were encountered: