lc0815

lc0815

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

Showing Posts 1 to 10

kip

kip

ex_cldr Core Team

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.

lc0815

lc0815 OP

thank you for your answer, will add it now…

lc0815

lc0815 OP

the new controller file now looks like this:

defmodule PhxReactList7Web.BlogsController do
  use PhxReactList7Web, :controller

  alias PhxReactList7.Blogs
  alias PhxReactList7.Repo

  def index(conn, _params) do
    blogs = Repo.all(Blogs)
    render conn, "index.json", blogs: blogs
  end
end

and now I get the error:

protocol Ecto.Queryable not implemented for PhxReactList7.Blogs of type Atom, the given module does not provide a schema. This protocol is implemented for the following type(s): Atom, BitString, Ecto.Query, Ecto.SubQuery, Tuple

I guess my main problem is that I am totally confused where the schema and the database tables are defined and used inside the application as the steps described in the article do now correspond to the current version.

I have read both the controllers guides and the ecto guides but I still have not made the connection between the dots metaphorically.

I did the migration step and that worked, I then added a few records to the database so I’m good there.

ityonemo

ityonemo

Database tables are defined in the migrations. You didn’t create a schema in your .Blogs module

Ecto treats schemas separately from the database and does not autopopulate it for you. You can have more than one schema for any given database table, you can use that to enforce contextual boundaries on database columns access (context A needs to only see these columns and context B needs to only see these other columns)

lc0815

lc0815 OP

I did create a schema, the file name is blogs.ex under the blogs directory under the app directory

the file looks like this:

defmodule PhxReactList7.Blog do
  use Ecto.Schema
  import Ecto.Changeset

  schema "blogs" do
    field :title, :string
    field :subtitle, :string
    field :image, :string
    field :link, :string
    field :author, :string

    timestamps()
  end

  @doc false
  def changeset(blogs, attrs) do
    blogs
    |> cast(attrs, [:title, :subtitle, :image, :link, :author])
    |> validate_required([:title, :subtitle, :image, :link, :author])
  end
end

I followed the Ecto guides in creating the schema file, but I may have the object names wrong…

anywho: thank you for your great response…

kokolegorille

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

lc0815

lc0815 OP

I figured as much. I did just as are suggesting and created the friends mix app as shown in the Ecto guides but that demo does not go far enough as it does not have a front end section to the example that uses the created schema/tables context

I will start all over again by reading about context and other things and also I will put the project in github so I don’t have to cut and paste like I’m doing now..

the Blogs, Blogs.blog, blogs and other bloggie issues did not work for me… again because of the 1.3 to 1.5 incompatibility issue and there does not seem to be any docs that amplify or describe the way to go from one to the other…

Thanks

lc0815

lc0815 OP

Oh boy have I been into google, but sometimes friends do not understand what you are trying to ask or the questions do not make any sense to your friend, so the answers do not help.

No prob, will continue to google, and to bing it with edge as well.

Thanks again, will read the medium article since I also am a subscriber…

ityonemo

ityonemo

just to be clear, you need to pass the PhxReactList7.Blog module to the repo function. Currently you are passing the PhxReactList7.Blogs module to the repo function.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews