Single Model fetch retrieve other model values too #194
-
Using same PK value for two models (RuleViolationSeverity, Catalog). When i find the values for RuleViolationSeverity with PK values, it retrives the results of model 'Catalog' too. So i just added _type in the find query, even though facing the same issue. Kindly help me here.
await ruleViolationSeverity.find( |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Can you provide more information -- can't follow you code snippet without context. What issue are you referencing? |
Beta Was this translation helpful? Give feedback.
-
In general, find will use the properties you provide to create the PK/SK for the query. These properties may be the PK/SK directly or may be other properties that are used in value templates (preferred approach). If PK/SK are provided directly, they take precedence. find has a special case where if you omit the full SK ingredients for a value template, find will use the leading fixed prefix portion and do a find using begins_with. In this way, you can use partial SK fields where SK is overloaded. If you provide _type, it is used in the filterExpression which you would see via the log: true param to see the DynamoDB command as per the README. This is not best practice and you should design your keys and GSIs so that you can retrieve items by type directly without a filterExpression. |
Beta Was this translation helpful? Give feedback.
In general, find will use the properties you provide to create the PK/SK for the query. These properties may be the PK/SK directly or may be other properties that are used in value templates (preferred approach). If PK/SK are provided directly, they take precedence.
find has a special case where if you omit the full SK ingredients for a value template, find will use the leading fixed prefix portion and do a find using begins_with. In this way, you can use partial SK fields where SK is overloaded.
If you provide _type, it is used in the filterExpression which you would see via the log: true param to see the DynamoDB command as per the README. This is not best practice and you should design…