File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 1
1
defmodule AshPostgres.AtomicsTest do
2
+ alias AshPostgres.Test.Author
2
3
use AshPostgres.RepoCase , async: false
3
4
alias AshPostgres.Test.Post
4
5
@@ -101,4 +102,23 @@ defmodule AshPostgres.AtomicsTest do
101
102
102
103
assert Post . increment_score! ( post , 2 ) . score == 4
103
104
end
105
+
106
+ test "use rel in atomic update" do
107
+ author =
108
+ Author
109
+ |> Ash.Changeset . for_create ( :create , % { first_name: "John" , last_name: "Doe" } )
110
+ |> Ash . create! ( )
111
+
112
+ post =
113
+ Post
114
+ |> Ash.Changeset . for_create ( :create , % { price: 1 , author_id: author . id } )
115
+ |> Ash . create! ( )
116
+
117
+ post =
118
+ post
119
+ |> Ash.Changeset . for_update ( :set_title_from_author , % { } )
120
+ |> Ash . update! ( )
121
+
122
+ assert post . title == "John"
123
+ end
104
124
end
Original file line number Diff line number Diff line change @@ -150,6 +150,10 @@ defmodule AshPostgres.Test.Post do
150
150
)
151
151
end
152
152
153
+ update :set_title_from_author do
154
+ change ( atomic_update ( :title , expr ( author . first_name ) ) )
155
+ end
156
+
153
157
update :increment_score do
154
158
argument ( :amount , :integer , default: 1 )
155
159
change ( atomic_update ( :score , expr ( ( score || 0 ) + ^ arg ( :amount ) ) ) )
You can’t perform that action at this time.
0 commit comments