dyna-record 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -264,6 +264,27 @@ class Course extends MyTable {
|
|
|
264
264
|
}
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
+
By default, a HasMany relationship is bi-directional—records are denormalized into both the parent and child entity partitions. This setup supports access patterns that allow each entity to retrieve its associated records. However, updating a HasMany entity requires updating its denormalized record in every associated partition, which can lead to issues given DynamoDB's 100-item transaction limit.
|
|
268
|
+
|
|
269
|
+
To mitigate this, you can specify uniDirectional in the HasMany decorator and remove the BelongsTo relationship from the child entity. With this configuration, only the parent-to-child access pattern is supported.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { Entity, NullableForeignKey, BelongsTo, HasMany } from "dyna-record";
|
|
273
|
+
|
|
274
|
+
@Entity
|
|
275
|
+
class Teacher extends MyTable {
|
|
276
|
+
// 'teacherId' must be defined on associated model
|
|
277
|
+
@HasMany(() => Course, { foreignKey: "teacherId", uniDirectional: true })
|
|
278
|
+
public readonly courses: Course[];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@Entity
|
|
282
|
+
class Course extends MyTable {
|
|
283
|
+
@ForeignKeyAttribute({ nullable: true })
|
|
284
|
+
public readonly teacherId?: NullableForeignKey; // Mark as optional
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
267
288
|
### HasAndBelongsToMany
|
|
268
289
|
|
|
269
290
|
[Docs](https://dyna-record.com/functions/HasAndBelongsToMany.html)
|