Skip to content

feat: Add offset option to has_one and has_many relationships#2584

Merged
zachdaniel merged 2 commits intoash-project:mainfrom
nallwhy:feature/relationship-offset
Feb 25, 2026
Merged

feat: Add offset option to has_one and has_many relationships#2584
zachdaniel merged 2 commits intoash-project:mainfrom
nallwhy:feature/relationship-offset

Conversation

@nallwhy
Copy link
Contributor

@nallwhy nallwhy commented Feb 24, 2026

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Summary

  • Add offset option to has_one and has_many relationship DSL
  • offset on has_one implies from_many?: true to ensure lateral joins

Closes #1740

Copilot AI review requested due to automatic review settings February 24, 2026 00:13
@nallwhy nallwhy changed the title Add offset option to has_one and has_many relationships feat: Add offset option to has_one and has_many relationships Feb 24, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 offset option to Ash.Resource.Relationships.HasOne and HasMany DSL/entities.
  • Apply relationship-level offset during relationship query construction/loading.
  • Add unit/behavior tests covering offset (and limit slicing) plus formatter support for offset 1 DSL 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.

@zachdaniel
Copy link
Contributor

@nallwhy this looks good, but we will also need to add this option to ash_sql for joining and for ash_postgres in its lateral join code.

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>
@zachdaniel zachdaniel merged commit 428f6cf into ash-project:main Feb 25, 2026
43 of 49 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.

Add offet / limit to has_many and has_one relationships

3 participants