JimmyCarterSon

JimmyCarterSon

Seed Data with Elixir

Hello,

I am working on a new application with Elixir, Dish_out. I want to see Data I follow this tutorial with Elixir Casts. However, I am not sure if what I am doing is correct because my seed file does not work.
My Seed File:

alias DishOut.Recipes

Recipes.insert!(
    %{title: "Mac N Cheese", ingredients: "Elbow Pasta, Milk, Cheese, Heavy cream", summary: "Bring pasta to a boil for 10 mins, drain water, add milk, cream, and cheese in. Stir and allow to cool before consuming.", date: "032022"}
)

In video the moderator alias another file, what is that file?

Marked As Solved

kokolegorille

kokolegorille

There is no insert! function in the Food structure. And Foods should be the module used to create Food struct.

You cannot invent function name, it needs to exists in the file.

  @doc """
  Creates a food.
  ## Examples
      iex> create_food(%{field: value})
      {:ok, %Food{}}
      iex> create_food(%{field: bad_value})
      {:error, %Ecto.Changeset{}}
  """
  def create_food(attrs \\ %{}) do
    %Food{}
    |> Food.changeset(attrs)
    |> Repo.insert()
  end

The closest is this one, and should be used like this…

DishOut.Foods.create_food(attrs)

Also Liked

kokolegorille

kokolegorille

Looking at the code… there is no module called Recipes.

One is called Foods, but not Recipes.

Hmm? No error message?

You might test this in the console directly.

JimmyCarterSon

JimmyCarterSon

Yes, Recipes don’t exist. I thought we were creating a new one to seed the file?

What do I reference my Schema which is “Delish_foods”

so would it alias DishOut.Delish_foods?

sorry I am a beginner this si my first time seeding a file in elixir.

kokolegorille

kokolegorille

The github repo You are following looks like a beginner repo too.

The right name should be DishOut.Foods.Food

delish_foods is the name of the table.

PS. I did not watch the screencast, so I don’t know what’s in.

Where Next?

Popular Backend topics Top

chasekaylee
Hi there everyone! Recently, I have fallen in love with programming with Elixir and have been having so much fun with it. I have been do...
New
New
Rainer
Is there somewhere a good introduction to rust for experienced programmers (with years of C++/C#/Java experience)? Wanted to give it a t...
New
IhorYachmenov
Hello. I have an iOS app where needs a proxying website through private server(HTTP / HTTPS proxy), but its idea each time has some trou...
New
sampu
I have a use case where a client is invoking a Rest endpoint via a load balancer, which in turn invokes a third party endpoint which is r...
New
GermaVinsmoke
Does anyone know beginner friendly Elixir/Phoenix Open source projects? For learning purpose :slightly_smiling_face:
New
Fl4m3Ph03n1x
Background PS: the following situation describes an hypothetical scenario, where I own a company that sells things to customers. I have ...
New
New
harwind
I’m presently working on a backend development project to build a RESTful API using Python and Flask. The Scaler backend developer site h...
New
Fl4m3Ph03n1x
Background I have a release file inside a tarball. However I want the final release to have some additional files and to move things aro...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1030 17300 381
New
AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New