Skip to content

#7 feat: add belongs_to and has_many relation support#33

Merged
RAprogramm merged 2 commits intodevfrom
7
Jan 5, 2026
Merged

#7 feat: add belongs_to and has_many relation support#33
RAprogramm merged 2 commits intodevfrom
7

Conversation

@RAprogramm
Copy link
Owner

Summary

  • Add #[belongs_to(Entity)] field attribute for foreign key relations
  • Add #[has_many(Entity)] entity attribute for one-to-many relations
  • Generate find_{entity} methods for belongs_to relations (returns Option<Entity>)
  • Generate find_{entities} methods for has_many relations (returns Vec<Entity>)

Changes

  • src/entity/parse/field/storage.rs: Add belongs_to field to StorageConfig
  • src/entity/parse/field.rs: Parse #[belongs_to(Entity)] attribute
  • src/entity/parse/entity.rs: Parse #[has_many(Entity)] attributes, add has_many field
  • src/entity/repository.rs: Generate trait methods for both relation types
  • src/entity/sql/postgres.rs: Implement PostgreSQL methods for relations
  • src/lib.rs: Register belongs_to and has_many attributes
  • README.md: Add Relations section with examples

Closes #7

- Add #[belongs_to(Entity)] field attribute for foreign key relations
- Add #[has_many(Entity)] entity attribute for one-to-many relations
- Generate find_{entity} methods for belongs_to relations
- Generate find_{entities} methods for has_many relations
- Implement PostgreSQL repository methods for both relation types
- Update documentation with relation examples
@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

When multiple entities with relations are in the same file,
PgPool implements multiple repository traits with find_by_id methods.
Use <Self as Trait>::find_by_id() to disambiguate.
@RAprogramm RAprogramm merged commit c4b619b into dev Jan 5, 2026
16 checks passed
@RAprogramm RAprogramm deleted the 7 branch January 5, 2026 04:43
@RAprogramm RAprogramm linked an issue Jan 5, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relations support (belongs_to, has_many)

1 participant