lc0815
Function Repo.all/1 is undefined (module Repo is not available)
Hello one and all, I am trying to create a full stack app with react and phoenix from an article that uses phoenix 1.3 while I’m using the latest version 1.5.7. in the article, the models db access is used and version 1.5.7 no longer uses the models so my app gives me the following error when I send a get request from postman0
function Repo.all/1 is undefined (module Repo is not available)
The controller file
defmodule PhxReactList7Web.BlogsController do
use PhxReactList7Web, :controller
alias PhxReactList7.Blogs
def index(conn, _params) do
blogs = Repo.all(Blogs)
render conn, "index.json", blogs: blogs
end
end
the repo file
defmodule PhxReactList7.Repo do
use Ecto.Repo,
otp_app: :phx_react_list_7,
adapter: Ecto.Adapters.Postgres
end
the blogs file
defmodule PhxReactList7.Blogs do
import Ecto.Query, warn: false
end
Most Liked
kip
In the docs, Repo.fun/arity needs to be considered as MyApp.Repo.fun. So in your example, I would suggest adding alias PhxReactList7.Repo in your controller and you should be good to go.
kokolegorille
That’s the inconvenient following 1.3 tuto, there were no context and no schema, but models…
Also beware of Blog, Blogs, blog, blogs. Because You made some mistakes in the naming.
What You should have is something like PhxReactList7.Blogs.Blog with Blogs being the context, and blog being the schema.
I suggest You start a demo project and initialize a simple resource, and see how it is done with 1.5
With mix phx.gen.context
kokolegorille
Google is your friend ![]()
https://medium.com/adorableio/from-models-to-contexts-in-phoenix-1-3-0-1535d1d773b2
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









