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.
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 callingrecord.id
, which overrides theid_method_name
options passed into the relationship.I tried fixing this by only changing the code in
Relationship
to dynamically call theid_method_name
on the object, but unfortunately on has_many relationships the default value forid_method_name
would be passed as if the ids would be pulled in a batch (for examplegroupee_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 toid
rather thanid_method_name_from_relationship
in the case where the relationship is polymorphic.