File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,29 @@ defmodule Ecto.Integration.CrudTest do
104104 assert changed . name == "Bob"
105105 end
106106
107+ test "update_all with select returns a row count of 0 when no records were updated" do
108+ { :ok , _lj } = TestRepo . insert ( % User { name: "Lebron James" } , [ ] )
109+
110+ no_match_query =
111+ from (
112+ a in Account ,
113+ where: a . name == "Michael Jordan" ,
114+ select: % { name: a . name }
115+ )
116+
117+ assert { 0 , nil } = TestRepo . update_all ( no_match_query , set: [ name: "G.O.A.T" ] )
118+
119+ match_query =
120+ from (
121+ a in Account ,
122+ where: a . name == "Lebron James" ,
123+ select: % { name: a . name }
124+ )
125+
126+ assert { 1 , % { name: "Lebron James" } } =
127+ TestRepo . update_all ( no_match_query , set: [ name: "G.O.A.T" ] )
128+ end
129+
107130 test "update_all handles null<->nil conversion correctly" do
108131 account = TestRepo . insert! ( % Account { name: "hello" } )
109132 assert { 1 , nil } = TestRepo . update_all ( Account , set: [ name: nil ] )
You can’t perform that action at this time.
0 commit comments