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.

Popular Backend topics Top

PragmaticBookshelf
TDD is a modern programming practice that all C developers need to know. It’s a different way to program—unit tests are written in a tigh...
New
bot
Kotlin v1.4.0 has been released. Link: Release Kotlin 1.4.0 · JetBrains/kotlin · GitHub
New
AstonJ
Consider this Erlang code: Rectangle = {rectangle, 20, 10}. {rectangle, Width, Height} = Rectangle. > Width. 20 > Height. 10 When...
New
Kurisu
Hello and happy new year! I would like to buy a Ruby On Rails ebook for learning purpose. What would be the ROR equivalent of “Programm...
New
New
First poster: OvermindDL1
Today we are happy to announce axum: An easy to use, yet powerful, web framework designed to take full advantage of the Tokio ecosystem. ...
New
PragmaticBookshelf
Use WebRTC to build web applications that stream media and data in real time directly from one user to another, all in the browser. ...
New
First poster: bot
Node.js v14.19.0 has been released. Link: Release 2022-02-01, Version 14.19.0 'Fermium' (LTS), @richardlau · nodejs/node · GitHub
New
ManningBooks
Effectively reading and understanding existing code is a developer’s superpower. In this book, you’ll master techniques for code profilin...
New
PragmaticBookshelf
Create Android applications using Jetpack Compose 1.6, Android Studio, Material Design 3, and the Kotlin programming language. Neil...
New

Other popular topics Top

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New