Updated handling of multiple relationships between same records#167
Updated handling of multiple relationships between same records#167
Conversation
|
I agree that there is a fundamental issue with the API for serializing related records here. It seems like what we should be doing is using a separate Relationship serializer, once per relationship. That would include the relationship's UUID, related type, UDFs on the relationship, etc. Then an endpoint like Instead it seems like we are serializing each related Person record using the Person serializer class (for example). I see why, because we do want some/all of the fields from the related record's own serializer class, but it seems equally important that we get relationship record data serialized. Otherwise, there's no way to know that a record in the returned list is actually getting data like UUID and UDFs from the correct relationship with the primary record. You'd have to aggregate both into lists, and it wouldn't be clear which belong with which. So yeah, I don't think I suspect this involves changes to this API routing, where we want to resolve each of these to filtered lists of relationships rather than of related model instances. Might involve upstream changes in |
This is very helpful and validating, thanks for taking a look! These are exactly my thoughts, put more eloquently. With the current setup using the Person serializer I couldn't wrap my brain around any way to track which item corresponds to which row of the
Okay that makes sense! Next question (maybe for @absempere or @jamiefolsom?) is what this means about dealing with the issue of duplicate related records appearing to be displayed on consuming apps, e.g. NBU, since they're launching in just over a month. Is it realistic to get this change implemented by then? Should I try to do some sort of temporary fix on the front end until this is fixed? (For example querying Typesense instead of the FairData API to get the relationship UUID.) |
In this PR
This is an initial attempt at addressing performant-software/core-data-cloud#509 by updating how we handle the case of multiple relationships between the same pair of records, so that the returned array will have only one entry for each related record, and when applicable the
project_model_relationship_uuidfield will contain an array of the UUIDs of all relationships between them.Issues and questions
project_model_relationship_uuidfield is different.project_model_relationship_inversefield...really in the case of multiple relationships that should also be an array, but I couldn't figure out how to get it to line up. In fact it seems like right now we're making the assumption that at least one ofitem.relationshipsanditem.related_relationshipsis empty (seecore-data-connector/app/serializers/concerns/core_data_connector/public/v1/typeable_serializer.rb
Line 20 in d4a600c
.distinctmethod, since the field we're ordering by is only in the joined table...I'm sure there's a way but this seemed to be just outside my ability to decipher Rails stuff.