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

id_method_name not respected with polymorphic association #382

Open
doits opened this issue Jan 22, 2019 · 3 comments · May be fixed by #384
Open

id_method_name not respected with polymorphic association #382

doits opened this issue Jan 22, 2019 · 3 comments · May be fixed by #384

Comments

@doits
Copy link

doits commented Jan 22, 2019

Version: 1.5

Without polymorphic association, I can do:

  belongs_to(
    :event,
    id_method_name: :event_uuid,
  )

It correctly uses event_uuid as the method to get the id of the association.

With polymorphic though:

  belongs_to(
    :resource,
    id_method_name: :resource_uuid,
    polymorphic: true
  )

id_method_name has no effect, it always uses resource_id as the id. I think this is a bug?

@doits doits linked a pull request Jan 26, 2019 that will close this issue
@thisismydesign
Copy link

Can verify, also think this is a bug.

@thisismydesign
Copy link

If this is a dealbreaker for someone I think you can work around it like this:

  • Use record_type: { Image: :image, etc }, this allows to use id_method_name and sets types correctly
  • Create a single serializer for the polymorphic association. E.g. ResourceSerializer
  • In ResourceSerializer use conditional attributes based on type, like so:
attributes :widht, :height, if: proc { |record, _params|
  record.class == Image
}

I'm not sure how/if relationships would work in this case.

@maxKimoby
Copy link

This is still a bug and makes the use of polymorphic serialization difficult.

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 a pull request may close this issue.

3 participants