- Introduced hook decorators for lifecycle methods in models. - Documented @Model decorator for model configuration. - Added relationship decorators for defining model relationships. - Created MigrationBuilder and MigrationManager documentation for schema migrations. - Added QueryExecutor and RelationshipManager documentation for query execution and relationship handling. - Included examples for complex queries and migration scenarios. - Developed a social platform example showcasing model relationships and application structure. - Enhanced contributing guidelines with community, documentation, and release processes. - Established testing guidelines for unit and integration tests.
55 lines
1.1 KiB
Markdown
55 lines
1.1 KiB
Markdown
---
|
|
sidebar_position: 6
|
|
---
|
|
|
|
# RelationshipManager
|
|
|
|
The `RelationshipManager` handles model relationships and data loading in DebrosFramework.
|
|
|
|
## Overview
|
|
|
|
The RelationshipManager manages relationships between models, handles lazy and eager loading, and provides relationship caching for performance optimization.
|
|
|
|
## Class Definition
|
|
|
|
```typescript
|
|
class RelationshipManager {
|
|
constructor(
|
|
private databaseManager: DatabaseManager,
|
|
private queryExecutor: QueryExecutor
|
|
);
|
|
}
|
|
```
|
|
|
|
## Core Methods
|
|
|
|
### Relationship Loading
|
|
|
|
#### `loadRelationship<T>(model, relationship)`
|
|
|
|
Loads a relationship for a model instance.
|
|
|
|
```typescript
|
|
async loadRelationship<T>(
|
|
model: BaseModel,
|
|
relationship: string
|
|
): Promise<T | T[]>
|
|
```
|
|
|
|
**Parameters:**
|
|
- `model` - The model instance
|
|
- `relationship` - The relationship name to load
|
|
|
|
**Returns:** Promise resolving to related model(s)
|
|
|
|
**Example:**
|
|
```typescript
|
|
const user = await User.findById('user123');
|
|
const posts = await relationshipManager.loadRelationship(user, 'posts');
|
|
```
|
|
|
|
## Related Classes
|
|
|
|
- [`BaseModel`](./base-model) - Base model class
|
|
- [`QueryExecutor`](./query-executor) - Query execution
|