I noticed that when my app shared the same module name as one of my resources, things get weird. This might be a noob mistake, but since I’m developing a microservice dedicated for interacting with a single resource, it did make sense to name the app after the resource. I was working on getting pagination working on my JSON index endpoint – I followed the article on https://www.dailydrip.com/topics/elixirsips/drips/phoenix-api-pagination-with-scrivener to get the scrivener_ecto
package (https://github.com/drewolson/scrivener_ecto) working.
When I start the Phoenix server, I got a warning like this:
warning: function Myresource.MyresourceCtx.Myresource.Repo.paginate/2 is undefined (module Myresource.MyresourceCtx.Myresource.Repo is not available)
My controller uses a simple alias:
alias Myresource.Repo
def index(conn, params) do
page =
Myresource
|> Repo.paginate(params)
conn
|> Scrivener.Headers.paginate(page)
|> render("index.json", resource: page.entries)
end
So it looks like Elixir gets confused by that name… Repo.paginate
isn’t a method on Myresource.MyresourceCtx.Myresource.Repo
– it’s a method on Myresource.Repo
. I know I shouldn’t have named my application this way, but why does Elixir get confused?
(I was able to get this working on a separate Phoenix app where I didn’t mix up my module names).