Skip to content

feat: implement QuerySet.select_related - #67

Merged
Einswilli merged 2 commits into
AllDotPy:masterfrom
mugenkyou:master
Sep 16, 2026
Merged

Einswilli merged 2 commits into
AllDotPy:masterfrom
mugenkyou:master

Conversation

@mugenkyou

Copy link
Copy Markdown
Contributor

Summary

Implements QuerySet.select_related() for single-level relationships.

Previously, select_related() returned a cloned QuerySet, but the requested relationship was not applied when the query was executed. This adds the query planning and row reconstruction needed to eagerly load related objects.

Changes

  • Preserve select_related() state when cloning and chaining a QuerySet
  • Add extra_alias support to the Python plan builder
  • Generate qualified columns and LEFT OUTER JOINs for related models
  • Alias related columns using the relationship name
  • Reconstruct related model instances from joined rows
  • Handle nullable foreign-key relationships
  • Keep count() and exists() independent of select_related()
  • Add integration tests for cloning, SQL generation, eager loading, nullable relationships, and count()/exists()
  • Update the select_related() documentation

Scope

This implementation is limited to single-level relationships. Nested lookups such as author__company are intentionally not included.

Testing

  • pytest ryx-python/tests/integration/test_select_related.py
  • cargo check

Both pass successfully.

Closes #64

@Wgoeh Wgoeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 👍🏾 thanks.
Everything looks cleaner.

@Einswilli Einswilli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

@Einswilli
Einswilli merged commit 6c23b64 into AllDotPy:master Sep 16, 2026
3 of 4 checks passed
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.

Fix QuerySet.select_related() eager loading

3 participants