Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: first draft of a unit test to reproduce this type of issue: #439

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/sql_implementation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,21 @@ defmodule AshPostgres.SqlImplementation do
end

def expr(
query,
%Ash.Query.Ref{
attribute: %Ash.Resource.Attribute{
type: attr_type,
constraints: constraints,
},
bare?: true
} = ref,
bindings,
embedded?,
acc,
type
) do
query,
%Ash.Query.Ref{
attribute: %Ash.Resource.Attribute{
type: attr_type,
constraints: constraints
},
bare?: true
} = ref,
bindings,
embedded?,
acc,
type
) do
if function_exported?(attr_type, :postgres_reference_expr, 3) do
non_bare_ref = %Ash.Query.Ref{ ref | bare?: nil }
non_bare_ref = %Ash.Query.Ref{ref | bare?: nil}
{expr, acc} = AshSql.Expr.dynamic_expr(query, non_bare_ref, bindings, embedded?, type, acc)

case attr_type.postgres_reference_expr(attr_type, constraints, expr) do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "role",
"type": "text"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "was_cancelled_at",
"type": "utc_datetime"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": true,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "co_authored_posts_author_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "authors"
},
"size": null,
"source": "author_id",
"type": "uuid"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": true,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "co_authored_posts_post_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "posts"
},
"size": null,
"source": "post_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "E1F2AC3AED1987928E3A2446584C268EC54D0BCA616D81A495F4AB26E3999444",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.AshPostgres.TestRepo",
"schema": null,
"table": "co_authored_posts"
}
48 changes: 48 additions & 0 deletions priv/test_repo/migrations/20241208221219_migrate_resources44.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
defmodule AshPostgres.TestRepo.Migrations.MigrateResources44 do
@moduledoc """
Updates resources based on their most recent snapshots.

This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
create table(:co_authored_posts, primary_key: false) do
add(:role, :text, null: false)
add(:was_cancelled_at, :utc_datetime)

add(
:author_id,
references(:authors,
column: :id,
name: "co_authored_posts_author_id_fkey",
type: :uuid,
prefix: "public"
),
primary_key: true,
null: false
)

add(
:post_id,
references(:posts,
column: :id,
name: "co_authored_posts_post_id_fkey",
type: :uuid,
prefix: "public"
),
primary_key: true,
null: false
)
end
end

def down do
drop(constraint(:co_authored_posts, "co_authored_posts_author_id_fkey"))

drop(constraint(:co_authored_posts, "co_authored_posts_post_id_fkey"))

drop(table(:co_authored_posts))
end
end
Loading
Loading