Skip to content

feat: add resource metadata to Ash.NotLoaded struct#2653

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
nallwhy:feat/not-loaded-resource-metadata
Mar 31, 2026
Merged

feat: add resource metadata to Ash.NotLoaded struct#2653
zachdaniel merged 1 commit intoash-project:mainfrom
nallwhy:feat/not-loaded-resource-metadata

Conversation

@nallwhy
Copy link
Copy Markdown
Contributor

@nallwhy nallwhy commented Mar 31, 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 a resource field to Ash.NotLoaded struct so consumers can identify which resource a not-loaded field belongs to
  • Populate resource in all places where Ash.NotLoaded is constructed: struct defaults (relationships, aggregates, calculations) and action helpers (attributes)
  • Show resource in standalone Ash.NotLoaded inspect output, but hide it inside resource record inspect to keep output clean

Closes #885

Copilot AI review requested due to automatic review settings March 31, 2026 09:32
@nallwhy nallwhy force-pushed the feat/not-loaded-resource-metadata branch from 91ac4c7 to 1d4ab88 Compare March 31, 2026 09:32
@nallwhy nallwhy force-pushed the feat/not-loaded-resource-metadata branch from 1d4ab88 to dab7918 Compare March 31, 2026 09:33
Copy link
Copy Markdown

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 resource metadata to Ash.NotLoaded so callers can identify which resource a not-loaded field belongs to, while keeping resource record inspect/1 output uncluttered.

Changes:

  • Added :resource field to %Ash.NotLoaded{} and updated its Inspect implementation to optionally display it.
  • Populated resource when constructing %Ash.NotLoaded{} in resource struct defaults (relationships/aggregates/calculations) and attribute select masks.
  • Updated resource record inspection to mark nested inspection as in_resource? so Ash.NotLoaded can hide resource in that context, and added tests covering defaults + inspect behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/ash/not_loaded.ex Adds resource to the struct/typespec and conditionally renders it in Inspect.
lib/ash/resource/schema.ex Ensures struct default %Ash.NotLoaded{} values include resource: __MODULE__ for relationships/aggregates/calculations.
lib/ash/actions/helpers.ex Includes resource in %Ash.NotLoaded{} created for unselected attributes in select masks.
lib/ash/resource.ex Sets Inspect custom option in_resource?: true when inspecting resource fields so nested NotLoaded hides resource.
test/not_loaded_test.exs Adds unit tests for the new resource field and inspect behavior (standalone vs inside resource).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zachdaniel zachdaniel merged commit 851d78e into ash-project:main Mar 31, 2026
40 of 45 checks passed
@zachdaniel
Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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 more metadata to Ash.NotLoaded and Ash.NotSelected.

3 participants