-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededonlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week
Description
Feature: Explicit Association Support
Add explicit support for handling associations between different factory types, making it easier to create related entities.
Context
The library already has database adapter examples (Prisma, Mongoose, TypeORM) that show how to persist data. This feature would add first-class support for defining relationships between factories in an ORM-agnostic way.
Proposed Features
associationmethod - Define a relationship to another factoryhasManymethod - Define one-to-many relationshipshasOnemethod - Define one-to-one relationshipsbelongsTomethod - Define inverse relationships- Handle circular references properly - Prevent infinite loops
- Support for sharing associated instances - Reuse associated objects
- Proper TypeScript types for associations - Full type safety
Implementation Requirements
- ORM-agnostic implementation that works with any persistence layer
- Reference existing database adapter examples for patterns
- Consider transaction support implications
- Handle performance for large association graphs
- Provide clear documentation on memory usage patterns
Example API
const UserFactory = new Factory<User>((faker) => ({
id: faker.string.uuid(),
name: faker.person.fullName(),
email: faker.internet.email()
}));
const PostFactory = new Factory<Post>((faker) => ({
id: faker.string.uuid(),
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(),
author: faker.association(UserFactory), // Creates associated user
authorId: faker.association(UserFactory, 'id') // Just the ID
}));
const BlogFactory = new Factory<Blog>((faker) => ({
id: faker.string.uuid(),
name: faker.company.name(),
owner: faker.hasOne(UserFactory),
posts: faker.hasMany(PostFactory, { count: 5 }) // Create 5 posts
}));
// Share associations
const user = UserFactory.build();
const posts = PostFactory.batch(10, { author: user, authorId: user.id });
// With persistence
const blog = await BlogFactory.buildAsync({}, {
adapter: prismaAdapter,
cascade: true // Save all associations
});Performance Considerations
- Lazy loading vs eager loading strategies
- Batch creation optimization
- Memory usage for large graphs
- Transaction batching for database operations
Testing Requirements
- Unit tests for each association type
- Integration tests with sample adapters
- Performance tests for large association graphs
- Circular reference handling tests
- Type safety verification tests
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededonlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week