Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Preload Functionality with Custom Joins and Add Comprehensive Tests #7293

Closed
wants to merge 3 commits into from

Conversation

soleinjast
Copy link

Checklist

  • Do only one thing
  • Non-breaking API changes
  • Tested

What did this pull request do?

This pull request enhances the preload functionality in GORM by:

  • Adding support for custom SQL joins with conditions when preloading associations.
  • Improving nested preload behavior with better flexibility for user-defined joins and conditions.

Additionally:

  • Updated the preload.go and query.go files to handle these customizations seamlessly.
  • Included comprehensive test cases to validate the new functionality and edge cases, ensuring robustness.

User Case Description

The changes allow developers to:

  1. Preload associations with custom SQL logic, such as filtering associated records (Tags with Status = "active").
  2. Handle nested associations with custom joins (e.g., preloading Tags.SubTags with conditions).
  3. Prevent errors for invalid SQL joins and improve error handling.

These enhancements address common use cases where developers need fine-grained control over how related data is preloaded in GORM.

Additional Notes

  • Tests were added to cover scenarios like:
    • Basic preloading with default behavior.
    • Custom joins with conditions for preloading.
    • Nested preload with custom joins.
    • Handling no matching records, empty databases, and invalid SQL.
    • Validation of edge cases with multiple items and different relationships.
  • Changes are backward-compatible and maintain existing preload functionality.

Let me know if you'd like me to refine this further! Once you submit the PR, be ready to address feedback from the GORM maintainers.

@soleinjast soleinjast closed this Nov 26, 2024
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.

1 participant