feat: Add offset option to has_one and has_many relationships#2584
Merged
zachdaniel merged 2 commits intoash-project:mainfrom Feb 25, 2026
Merged
feat: Add offset option to has_one and has_many relationships#2584zachdaniel merged 2 commits intoash-project:mainfrom
zachdaniel merged 2 commits intoash-project:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class offset support to relationship DSL for has_one and has_many, enabling “nth record”/sliced relationship loads without manual relationships. For has_one, using offset implicitly switches to from_many?: true so the loader uses the correct lateral-join behavior.
Changes:
- Add
offsetoption toAsh.Resource.Relationships.HasOneandHasManyDSL/entities. - Apply relationship-level
offsetduring relationship query construction/loading. - Add unit/behavior tests covering
offset(andlimitslicing) plus formatter support foroffset 1DSL style.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/ash/resource/relationships/has_one.ex |
Adds :offset field/DSL option; offset implies from_many?: true. |
lib/ash/resource/relationships/has_many.ex |
Adds :offset field/DSL option to has_many. |
lib/ash/actions/read/relationships.ex |
Applies relationship offset when building relationship queries. |
test/resource/relationships/has_one_test.exs |
Tests has_one DSL representation includes offset and implied from_many?. |
test/resource/relationships/has_many_test.exs |
Tests has_many DSL representation includes offset and limit. |
test/actions/has_many_test.exs |
End-to-end load tests verifying has_one offset selection and has_many offset+limit slicing. |
.formatter.exs |
Allows offset 1 without parentheses in formatted DSL blocks. |
.github/CONTRIBUTING.md |
Fixes numbering in DSL documentation improvement checklist. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@nallwhy this looks good, but we will also need to add this option to |
nallwhy
added a commit
to nallwhy/ash_sql
that referenced
this pull request
Feb 25, 2026
Adds offset support to the SQL join layer for has_one and has_many relationships. This works alongside the offset option being added to Ash core (ash-project/ash#2584). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributor checklist
Leave anything that you believe does not apply unchecked.
Summary
offsetoption tohas_oneandhas_manyrelationship DSLoffsetonhas_oneimpliesfrom_many?: trueto ensure lateral joinsCloses #1740