poc: extend exists/2 to traverse embedded array attributes#754
Draft
nallwhy wants to merge 4 commits into
Draft
Conversation
…butes # Conflicts: # test/support/domain.ex
There was a problem hiding this comment.
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 backingembedded_array_estimates/embedded_array_companies. - Adds
test/embedded_array_exists_test.exscovering type casts, composition, nestedexists, mixed relationship→embedded paths, and SQL edge cases (empty/nil arrays). - Declares
can?(_, {:exists, :embedded_array}) -> trueinlib/data_layer.exwithout 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.
|
|
||
| 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: [] |
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.
poc of ash-project/ash#2698