phoenix-chat-example icon indicating copy to clipboard operation
phoenix-chat-example copied to clipboard

Getting error: Ecto.Queryable not implemented for Message

Open abraidotti opened this issue 6 years ago • 7 comments

Hey there. I've followed the tutorial and adjusted my postgres databases, so everything works except querying the db to grab the last 20 saved messages. Here's what I get after I run mix phx.server:

Compiling 1 file (.ex) [info] Running ChatWeb.Endpoint with Cowboy using http://0.0.0.0:4000 14:09:40 - info: compiled 6 files into 2 files, copied 3 in 1.6 sec [warn] Ignoring unmatched topic "room:lobby" in ChatWeb.UserSocket [warn] Ignoring unmatched topic "room:lobby" in ChatWeb.UserSocket [info] JOIN "room:lobby" to ChatWeb.RoomChannel Transport: Phoenix.Transports.WebSocket (2.0.0) Serializer: Phoenix.Transports.V2.WebSocketSerializer Parameters: %{} [info] Replied room:lobby :ok [error] GenServer #PID<0.389.0> terminating ** (Protocol.UndefinedError) protocol Ecto.Queryable not implemented for Message, the given module does not exist. This protocol is implemented for: Atom, BitString, Ecto.Query, Ecto.SubQuery, Tuple (ecto) lib/ecto/queryable.ex:37: Ecto.Queryable.Atom.to_query/1 (ecto) lib/ecto/repo/queryable.ex:34: Ecto.Repo.Queryable.all/4 (chat) lib/chat_web/channels/room_channel.ex:29: ChatWeb.RoomChannel.handle_info/2 (phoenix) lib/phoenix/channel/server.ex:258: Phoenix.Channel.Server.handle_info/2 (stdlib) gen_server.erl:616: :gen_server.try_dispatch/4 (stdlib) gen_server.erl:686: :gen_server.handle_msg/6 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 Last message: :after_join State: %Phoenix.Socket{assigns: %{}, channel: ChatWeb.RoomChannel, channel_pid: #PID<0.389.0>, endpoint: ChatWeb.Endpoint, handler: ChatWeb.UserSocket, id: nil, join_ref: "41", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Chat.PubSub, ref: nil, serializer: Phoenix.Transports.V2.WebSocketSerializer, topic: "room:lobby", transport: Phoenix.Transports.WebSocket, transport_name: :websocket, transport_pid: #PID<0.382.0>, vsn: "2.0.0"}

I'm new to Elixir/Phoenix, and I've searched around, but I can't find a solution to this error. Do you know what's going wrong here?

abraidotti avatar Mar 08 '18 19:03 abraidotti

@abraidotti can you create a repo on GitHub and push up your code so we can run it on our side to help with debugging?

nelsonic avatar Mar 08 '18 23:03 nelsonic

Git repo here: https://github.com/abraidotti/elixir-chat-app :)

abraidotti avatar Mar 09 '18 00:03 abraidotti

Had the same problem.

That worked for me:

Use : def get_messages(limit \ 20) do Chat.Repo.all(Chat.Message, limit: limit) end

Instead of: def get_messages(limit \ 20) do Chat.Repo.all(Message, limit: limit) end

By the way, I love this tutorial, please continue providing such great tutorials, its the best source for beginners like me to learn and there are still not many tutorials that are in version 1.3, so this is extremely helpful!

AndreasBraun2015 avatar Mar 14 '18 15:03 AndreasBraun2015

Awesome! That worked! Thanks a lot.

abraidotti avatar Mar 15 '18 15:03 abraidotti

@abraidotti glad you got it figured out. From reading your /lib/chat/message.ex you are missing the alias Chat.Message

Which should have been added to the message.ex file by the "generator" when it was created ... However, @AndreasBraun2015 is right and I actually prefer to do a "full path" reference to the table. 👍

nelsonic avatar May 01 '18 16:05 nelsonic

Closing as OP's issue is resolved. ✅

nelsonic avatar May 01 '18 16:05 nelsonic

Given that @comerc has opened a similar issue #10 it might be worth adding a section about this to the README.md ... 🤔

nelsonic avatar Sep 01 '18 06:09 nelsonic

Should no longer be an issue.

nelsonic avatar Dec 01 '22 02:12 nelsonic