Open mightymatth opened 5 years ago
Yeah, you are completely right. Dynamoid's associations don't work with sort keys and there is already issue about this problem (https://github.com/Dynamoid/dynamoid/issues/316).
Associations here are too simple and limited and require complete reimplementation. That's why this known issue still isn't fixed.
Sorry, I haven't look for open issue about that problem.
Anyway, is there any reason why we don't use query
(docs here) method instead of batch_get_item
when we have range key in our association? The same question for my previous issue #364.
Hmm, I don't understand your question.
Current behavior I would consider as a bug and support of association with composite primary key should be added.
From the other hand BatchGetItem is the most efficient and cheapest way to load items by primary key for both simple scalar primary key and composite one.
From the other hand BatchGetItem is the most efficient and cheapest way to load items by primary key for both simple scalar primary key and composite one.
I agree with you, it's the most efficient way, but only if you have both; the primary key and composite one. Using Query API instead of BatchGetItem API, we could be able to get items just with primary key, which would resolve our problem while listing associations with range key. This is maybe less efficient way, but maybe it's better to use Query API in these cases before any bigger refactoring on associations are being done. This is just a proposal which acts as a workaround. Just speaking out loud.
Using Query API instead of BatchGetItem API, we could be able to get items just with primary key, which would resolve our problem while listing associations with range key
I assume you meant partition key when wrote just with primary key
.
Yeah, Query api call with condition on partition key like id: [id1, id2, id3, ...]
will work for class with sort key (range key) and items with cached partition keys will be loaded. But result will contain associated models as well as some arbitrary models with different sort key (range key) but the same partition one. So result will contain both associated models and not associated.
I would say it would be very dangerous bug because it would be silent. Am I right?
Anyway, please provide some code example or prototype to ensure we are on the same page.
I assume you meant partition key when wrote
just with primary key
.
Yes, I was thinking about partition key.
I would say it would be very dangerous bug because it would be silent. Am I right?
I'm concerned about this too. I don't have so much practice with DynamoDB/Dynamoid so I don't have an answer at the moment. When I catch some time, I'll try to make changes and test if it works as expected, then we can discuss about it.
This issue is somehow related to #364.
Consider having following models.
Now I can create Attender, AttenderGroup and add attender to group.
Creating attender:
Creating attender group:
Assigning musician to her group:
But now when I want to list all my musicians in the group, I get this error:
I know that this is related to setting sort key on Attender; it only stores ids without store key (
:groups_ids=>#<Set: {"e30db0bc-3820-49d2-987b-5b073a9378d2"}>
) and when I try to list them, it usesbatch_get_item
method with wrong query parameters ({\"Keys\":[{\"id\":{\"S\":\"94326b26-dc3b-4a1e-aa2b-20f7d623bd49\"},\"full_name\":{\"NULL\":true}}]}
)I think that, at the moment, querying on associations can be used only without using sort keys. Also, I'm not sure that my statements are all correct because I'm new in DynamoDB.