Skip to content

Commit 7c8b89a

Browse files
committed
chore: add test
1 parent 2b50113 commit 7c8b89a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

test/calculation_test.exs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule AshPostgres.CalculationTest do
22
use AshPostgres.RepoCase, async: false
3-
alias AshPostgres.Test.{Account, Author, Comedian, Comment, Post, User}
3+
alias AshPostgres.Test.{Account, Author, Comedian, Comment, Post, Record, TempEntity, User}
44

55
require Ash.Query
66
import Ash.Expr
@@ -1016,4 +1016,18 @@ defmodule AshPostgres.CalculationTest do
10161016
def fred do
10171017
"fred"
10181018
end
1019+
1020+
test "calculation references use the appropriate schema" do
1021+
record = Record |> Ash.Changeset.for_create(:create, %{full_name: "name"}) |> Ash.create!()
1022+
1023+
TempEntity |> Ash.Changeset.for_create(:create, %{full_name: "name"}) |> Ash.create!()
1024+
1025+
full_name =
1026+
Record
1027+
|> Ash.Query.load(:temp_entity_full_name)
1028+
|> Ash.read_first!()
1029+
|> Map.get(:temp_entity_full_name)
1030+
1031+
assert full_name == "name"
1032+
end
10191033
end

test/support/resources/record.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,31 @@ defmodule AshPostgres.Test.Record do
1414
end
1515

1616
relationships do
17-
alias AshPostgres.Test.Entity
18-
19-
has_one :entity, Entity do
17+
has_one :entity, AshPostgres.Test.Entity do
2018
public?(true)
2119
no_attributes?(true)
2220

2321
read_action(:read_from_temp)
2422

2523
filter(expr(full_name == parent(full_name)))
2624
end
25+
26+
has_one :temp_entity, AshPostgres.Test.TempEntity do
27+
public?(true)
28+
source_attribute(:full_name)
29+
destination_attribute(:full_name)
30+
end
2731
end
2832

2933
postgres do
3034
table "records"
3135
repo AshPostgres.TestRepo
3236
end
3337

38+
calculations do
39+
calculate(:temp_entity_full_name, :string, expr(temp_entity.full_name))
40+
end
41+
3442
actions do
3543
default_accept(:*)
3644

0 commit comments

Comments
 (0)