Netflix / fast_jsonapi

No Longer Maintained - A lightning fast JSON:API serializer for Ruby Objects.
Apache License 2.0
5.07k stars 425 forks source link

fix id method bugs #446

Open aub opened 4 years ago

aub commented 4 years ago

For polymorphic has_many relations, instead of getting the ids in a batch, the code loops over each object to get its type and id. In Relationship#id_hash_from_record it was hardcoded to get the id by calling record.id, which overrides the id_method_name options passed into the relationship.

I tried fixing this by only changing the code in Relationship to dynamically call the id_method_name on the object, but unfortunately on has_many relationships the default value for id_method_name would be passed as if the ids would be pulled in a batch (for example groupee_ids). That default works for regular has_manys where we get the ids all at once but fails for polymorphic ones where it loops over each object.

So, fixing the problem required passing the polymorphic information to compute_id_method_name, which now defaults to id rather than id_method_name_from_relationship in the case where the relationship is polymorphic.

This also fixes a bug where the record_id is not carried over through inheritance.

kapilnarula commented 4 years ago

It seems Netflix has abandoned this project. The community created a new fork to continue supporting this project. Please refer

https://github.com/fast-jsonapi/fast_jsonapi

On Wed, Oct 30, 2019 at 2:07 AM Aubrey Holland notifications@github.com wrote:

For polymorphic has_many relations, instead of getting the ids in a batch, the code loops over each object to get its type and id. In Relationship#id_hash_from_record it was hardcoded to get the id by calling record.id, which overrides the id_method_name options passed into the relationship.

I tried fixing this by only changing the code in Relationship to dynamically call the id_method_name on the object, but unfortunately on has_many relationships the default value for id_method_name would be passed as if the ids would be pulled in a batch (for example groupee_ids). That default works for regular has_manys where we get the ids all at once but fails for polymorphic ones where it loops over each object.

So, fixing the problem required passing the polymorphic information to compute_id_method_name, which now defaults to id rather than id_method_name_from_relationship in the case where the relationship is polymorphic.

This also fixes a bug where the record_id is not carried over through inheritance.

You can view, comment on, or merge this pull request online at:

https://github.com/Netflix/fast_jsonapi/pull/446 Commit Summary

  • fix id method bugs

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Netflix/fast_jsonapi/pull/446?email_source=notifications&email_token=ACEAHZJA2D5AW5ZFBIXIFNTQRCNIDA5CNFSM4JGPEFC2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HVGF25A, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEAHZOO5WEGO6TXH6EPGTTQRCNIDANCNFSM4JGPEFCQ .