Skip to content

poc: extend exists/2 to traverse embedded array attributes#754

Draft
nallwhy wants to merge 4 commits into
ash-project:mainfrom
nallwhy:feat/embedded-array-exists
Draft

poc: extend exists/2 to traverse embedded array attributes#754
nallwhy wants to merge 4 commits into
ash-project:mainfrom
nallwhy:feat/embedded-array-exists

Conversation

@nallwhy
Copy link
Copy Markdown
Contributor

@nallwhy nallwhy commented May 17, 2026

Copilot AI review requested due to automatic review settings May 17, 2026 12:35
@nallwhy nallwhy marked this pull request as draft May 17, 2026 12:35
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

A proof-of-concept for ash-project/ash#2698 that aims to extend exists/2 to traverse {:array, EmbeddedResource} attributes by emitting jsonb_array_elements-based SQL. In its current state the PR sets up new test resources/migrations and an extensive test suite, and flips a data-layer capability flag, but does not include the actual SQL translation logic.

Changes:

  • Adds new test resources (Estimate, Option, LineItem, Company) wired into the test domain, plus two migrations and three resource snapshots backing embedded_array_estimates/embedded_array_companies.
  • Adds test/embedded_array_exists_test.exs covering type casts, composition, nested exists, mixed relationship→embedded paths, and SQL edge cases (empty/nil arrays).
  • Declares can?(_, {:exists, :embedded_array}) -> true in lib/data_layer.ex without an accompanying translation implementation.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/data_layer.ex Adds :embedded_array exists capability flag (no translation implementation included).
test/support/domain.ex Registers EmbeddedArray.Company and EmbeddedArray.Estimate resources.
test/support/embedded_array/estimate.ex New Postgres-backed resource with a {:array, Option} jsonb attribute and belongs_to :company.
test/support/embedded_array/company.ex New Postgres-backed resource with has_many :estimates.
test/support/embedded_array/option.ex New embedded resource with mixed-type attributes including {:array, LineItem}.
test/support/embedded_array/line_item.ex New embedded resource used for nested exists tests.
test/embedded_array_exists_test.exs Full Phase 2–5 test suite for exists/2 over embedded arrays.
priv/test_repo/migrations/20260515050043_migrate_resources68.exs Creates embedded_array_estimates table.
priv/test_repo/migrations/20260516132941_migrate_resources71.exs Manually trimmed migration adding company_id and embedded_array_companies.
priv/resource_snapshots/test_repo/embedded_array_estimates/20260515050043.json Initial snapshot for estimates table.
priv/resource_snapshots/test_repo/embedded_array_estimates/20260516132943.json Snapshot adding company_id FK.
priv/resource_snapshots/test_repo/embedded_array_companies/20260516132942.json Snapshot for new companies table.

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

Comment thread lib/data_layer.ex

def can?(_, {:aggregate, :unrelated}), do: true
def can?(_, {:exists, :unrelated}), do: true
def can?(_, {:exists, :embedded_array}), do: true
Comment on lines +4 to +6
`embedded_array_estimates`. Other autogenerated changes for unrelated
resources (interest/profile_interest schemas, classroom.public) were
trimmed out because those tables already exist in the local test DB.
Comment on lines +9 to +18
alias AshPostgres.Test.EmbeddedArray.LineItem

attributes do
attribute :name, :string, public?: true
attribute :total_amt, :decimal, public?: true
attribute :quantity, :integer, public?: true
attribute :active, :boolean, public?: true
attribute :tier, :atom, public?: true, constraints: [one_of: [:basic, :premium, :enterprise]]
attribute :valid_until, :utc_datetime, public?: true
attribute :line_items, {:array, LineItem}, public?: true, default: []
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.

2 participants