Skip to content
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

Demonstrate presence of bug mentioned in #1686 #1690

Closed

Conversation

bf4
Copy link
Member

@bf4 bf4 commented Apr 18, 2016

For use in #1688

ModelWithAssociations::CachingModelSerializer.new(model).associations(include_tree).each do |association|
associations << association
end
assert_equal [:author, :blog, :comments], associations.map(&:key).sort
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail as associations will be [:author, :author, :blog, :blog, :comments, :comments]

@beauby
Copy link
Contributor

beauby commented Apr 19, 2016

Fixed the serializer definition. Should pass tests now.

@@ -309,11 +309,27 @@ class CachingCommentSerializer < CommentSerializer
cache expires_in: 1.day, skip_digest: true
end

class CachingModelSerializer < ModelSerializer
class CachingModelSerializer < ActiveModel::Serializer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inheriting from ModelSerializer will make it inherit the associations definitions, and AMS currently does not support redefining associations, hence new associations with the same name will be added.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, weird

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the definitions were hashes that could only be defined once

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this bug 🐞 is essentially why all my benchmarks have shown a performance decrease until I memoized the associations? wow!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid so!

Copy link
Member Author

@bf4 bf4 Apr 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg

        def associate(reflection)
-          self._reflections << reflection
+          self._reflections[reflection.key] = reflection
        end

or is it reflection.name, anyhow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it's an array though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, meant diff as suggesting interface change rather than a working didd

On Tue, Apr 19, 2016 at 10:22 PM Lucas Hosseini notifications@github.com
wrote:

In test/fixtures/poro.rb
#1690 (comment)
:

@@ -309,11 +309,27 @@ class CachingCommentSerializer < CommentSerializer
cache expires_in: 1.day, skip_digest: true
end

  • class CachingModelSerializer < ModelSerializer
  • class CachingModelSerializer < ActiveModel::Serializer

Hmm it's an array though.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/rails-api/active_model_serializers/pull/1690/files/b3518271c473ef14e73463cd5e93897a3d8e3785..68715b8f99bc29677e8a47bb3f305f23c077024b#r60345797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants