Skip to content

Instantly share code, notes, and snippets.

@dmoulton
Created February 27, 2018 17:32
Show Gist options
  • Save dmoulton/c3580d53117a26f0182a04344b94d01e to your computer and use it in GitHub Desktop.
Save dmoulton/c3580d53117a26f0182a04344b94d01e to your computer and use it in GitHub Desktop.
Error received in Stephen Grider's course on Elixir and Phoenix at Udemy.com
[error] GenServer #PID<0.2560.0> terminating
** (RuntimeError) cannot encode association :user from Discuss.Comment to JSON because the association was not loaded. Please make sure you have preloaded the association or remove it from the data to be encoded
(ecto) lib/ecto/poison.ex:12: Poison.Encoder.Ecto.Association.NotLoaded.encode/2
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison.ex:41: Poison.encode!/2
(phoenix) lib/phoenix/transports/websocket_serializer.ex:14: Phoenix.Transports.WebSocketSerializer.fastlane!/1
(phoenix) lib/phoenix/channel/server.ex:269: anonymous fn/5 in Phoenix.Channel.Server.fastlane/3
(elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_pubsub) lib/phoenix/pubsub/local.ex:96: Phoenix.PubSub.Local.broadcast/6
(elixir) lib/enum.ex:737: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:737: Enum.each/2
(phoenix_pubsub) lib/phoenix/pubsub/pg2_server.ex:30: Phoenix.PubSub.PG2Server.do_broadcast/7
(phoenix_pubsub) lib/phoenix/pubsub.ex:212: Phoenix.PubSub.broadcast!/3
(discuss) web/channels/comments_channel.ex:24: Discuss.CommentsChannel.handle_in/3
Last message: %Phoenix.Socket.Message{event: "comment:add", payload: %{"content" => "second comment"}, ref: "2", topic: "comments:1"}
State: %Phoenix.Socket{assigns: %{topic: %Discuss.Topic{__meta__: #Ecto.Schema.Metadata<:loaded, "topics">, comments: [%Discuss.Comment{__meta__: #Ecto.Schema.Metadata<:loaded, "comments">, content: "first comment", id: 1, inserted_at: #Ecto.DateTime<2018-02-27 16:32:46>, topic: #Ecto.Association.NotLoaded<association :topic is not loaded>, topic_id: 1, updated_at: #Ecto.DateTime<2018-02-27 16:32:46>, user: nil, user_id: nil}], id: 1, title: "First Topic", user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 1}, user_id: 1}, channel: Discuss.CommentsChannel, channel_pid: #PID<0.2560.0>, endpoint: Discuss.Endpoint, handler: Discuss.UserSocket, id: nil, joined: true, pubsub_server: Discuss.PubSub, ref: nil, serializer: Phoenix.Transports.WebSocketSerializer, topic: "comments:1", transport: Phoenix.Transports.WebSocket, transport_name: :websocket, transport_pid: #PID<0.2558.0>}
@devconxol
Copy link

Please, how did you fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment