2

Is ruby's active_model_serializer (AMS) able to manage many to many relations?

For example:

class ProjectSerializer < ActiveModel::Serializer
    has_many :resources
end

class ResourcesSerializer < ActiveModel::Serializer
    has_many :projects
end

I'm getting 'stack level too deep' error.

Reference to this issue on AMS github repo: https://github.com/rails-api/active_model_serializers/issues/211

Based on the previous link I think this is not supported yet, but any elegant workarounds are welcome.

2 Answers 2

0

The reason you get an error "stack level too deep' is that it would be an infinite loop.

Each resource would list the projects it has which in turn would list the resources they have, which would list the projects again and so on.

You can use either one has_many but not both.

0

You need to use :has_and_belongs_to_many in both cases

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.