@@ -1840,6 +1840,23 @@ defmodule Ecto.Integration.RepoTest do
1840
1840
1841
1841
@ tag :with_conflict_target
1842
1842
test "on conflict query and conflict target" do
1843
+ on_conflict = from p in Post , where: p . id > ^ 0 , update: [ set: [ title: "second" ] ]
1844
+ post = [ title: "first" , uuid: Ecto.UUID . generate ( ) ]
1845
+ assert TestRepo . insert_all ( Post , [ post ] , on_conflict: on_conflict , conflict_target: [ :uuid ] ) ==
1846
+ { 1 , nil }
1847
+
1848
+ # Error on non-conflict target
1849
+ assert catch_error ( TestRepo . insert_all ( Post , [ post ] , on_conflict: on_conflict , conflict_target: [ :id ] ) )
1850
+
1851
+ # Error on conflict target
1852
+ assert TestRepo . insert_all ( Post , [ post ] , on_conflict: on_conflict , conflict_target: [ :uuid ] ) ==
1853
+ { 1 , nil }
1854
+ assert TestRepo . all ( from p in Post , select: p . title ) == [ "second" ]
1855
+ end
1856
+
1857
+ @ tag :insert_select
1858
+ @ tag :with_conflict_target
1859
+ test "on conflict query and insert select and conflict target" do
1843
1860
on_conflict = from p in Post , where: p . id > ^ 0 , update: [ set: [ title: "second" ] ]
1844
1861
visits_value = from p in Post , where: p . public == ^ true and p . id > ^ 0 , select: p . visits , limit: 1
1845
1862
post = [ title: "first" , uuid: Ecto.UUID . generate ( ) , visits: visits_value ]
0 commit comments