@@ -52,13 +52,20 @@ defmodule Ecto.Repo.ManyToManyTest do
5252 schema "my_schema" do
5353 field :x , :string
5454 field :y , :binary
55- many_to_many :assocs , MyAssoc , join_through: "schemas_assocs" , on_replace: :delete
55+
56+ many_to_many :assocs , MyAssoc ,
57+ join_through: "schemas_assocs" ,
58+ on_replace: :delete
5659
5760 many_to_many :where_assocs , MyAssoc ,
5861 join_through: "schemas_assocs" ,
5962 join_where: [ public: true ] ,
6063 on_replace: :delete
6164
65+ many_to_many :on_conflict_assocs , MyAssoc ,
66+ join_through: "schemas_assocs" ,
67+ on_join_through_conflict: :nothing
68+
6269 many_to_many :schema_assocs , MyAssoc ,
6370 join_through: MySchemaAssoc ,
6471 join_defaults: [ public: true ]
@@ -70,6 +77,10 @@ defmodule Ecto.Repo.ManyToManyTest do
7077 many_to_many :mfa_schema_assocs , MyAssoc ,
7178 join_through: MySchemaAssoc ,
7279 join_defaults: { __MODULE__ , :send_to_self , [ :extra ] }
80+
81+ many_to_many :on_conflict_schema_assocs , MyAssoc ,
82+ join_through: MySchemaAssoc ,
83+ on_join_through_conflict: :nothing
7384 end
7485
7586 def send_to_self ( struct , owner , extra ) do
@@ -107,10 +118,39 @@ defmodule Ecto.Repo.ManyToManyTest do
107118 assert assoc . inserted_at
108119 assert_received { :insert , _ }
109120
110- assert_received { :insert_all , % { source: "schemas_assocs" } ,
121+ assert_received { :insert_all , % { source: "schemas_assocs" , on_conflict: { :raise , [ ] , [ ] } } ,
111122 [ [ my_assoc_id: 1 , my_schema_id: 1 ] ] }
112123 end
113124
125+ test "handles assocs on insert with on_join_through_conflict and binary join_through" do
126+ sample = % MyAssoc { x: "xyz" }
127+
128+ changeset =
129+ % MySchema { }
130+ |> Ecto.Changeset . change ( )
131+ |> Ecto.Changeset . put_assoc ( :on_conflict_assocs , [ sample ] )
132+
133+ TestRepo . insert! ( changeset )
134+ assert_received { :insert , _ }
135+
136+ assert_received { :insert_all , % { source: "schemas_assocs" , on_conflict: { :nothing , [ ] , [ ] } } ,
137+ [ [ my_assoc_id: 1 , my_schema_id: 1 ] ] }
138+ end
139+
140+ test "handles assocs on insert with on_join_through_conflict and schema join_through" do
141+ sample = % MyAssoc { x: "xyz" }
142+
143+ changeset =
144+ % MySchema { }
145+ |> Ecto.Changeset . change ( )
146+ |> Ecto.Changeset . put_assoc ( :on_conflict_schema_assocs , [ sample ] )
147+
148+ TestRepo . insert! ( changeset )
149+ assert_received { :insert , _ }
150+
151+ assert_received { :insert , % { source: "schemas_assocs" , on_conflict: { :nothing , [ ] , [ ] } } }
152+ end
153+
114154 test "handles assocs on insert preserving parent schema prefix" do
115155 sample = % MyAssoc { x: "xyz" }
116156
0 commit comments