File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,8 @@ defmodule EctoWatch.WatcherServer do
184184 defp validate_subscription ( state , identifier , column ) do
185185 cond do
186186 match? ( { _ , :inserted } , identifier ) && column == state . options . schema_definition . primary_key ->
187- { :error , "Cannot subscribe to primary_key for inserted records" }
187+ { :error ,
188+ "Cannot subscribe to primary_key for inserted records because primary key values aren't created until the insert happens" }
188189
189190 column && not MapSet . member? ( state . identifier_columns , column ) ->
190191 { :error , "Column #{ column } is not an association column" }
Original file line number Diff line number Diff line change @@ -819,6 +819,23 @@ defmodule EctoWatchTest do
819819 end
820820
821821 describe "inserts" do
822+ test "Error when trying to subscribe to insert of an ID" do
823+ start_supervised! (
824+ { EctoWatch ,
825+ repo: TestRepo ,
826+ pub_sub: TestPubSub ,
827+ watchers: [
828+ { Thing , :inserted }
829+ ] }
830+ )
831+
832+ assert_raise ArgumentError ,
833+ ~r/ Cannot subscribe to primary_key for inserted records because primary key values aren't created until the insert happens/ ,
834+ fn ->
835+ EctoWatch . subscribe ( { Thing , :inserted } , 123 )
836+ end
837+ end
838+
822839 test "get notification about inserts" do
823840 start_supervised! ( { EctoWatch ,
824841 repo: TestRepo ,
You can’t perform that action at this time.
0 commit comments