dwyl / learn-phoenix

:fire: Phoenix is the web framework without compromise on speed, reliability or maintainability! Don't settle for less. :rocket:
649 stars 45 forks source link

p.168 attempting to create a video in iex get ** (KeyError) key :slug not found in: %Rumbl.Video{__meta__: #Ecto.Schema.Metadata<:built, "videos"> #51

Closed nelsonic closed 7 years ago

nelsonic commented 7 years ago

On page 168 of Programming Phoenix the instruction is to create a video. but when I attempt to run the command listed in the book

iex(1)> video = %Rumbl.Video{id: 1, slug: "hello"}

I get the an error ... 😞

Stack trace:

** (KeyError) key :slug not found in: %Rumbl.Video{__meta__: #Ecto.Schema.Metadata<:built, "videos">, category: #Ecto.Association.NotLoaded<association :category is not loaded>, category_id: nil, description: nil, id: 1, inserted_at: nil, title: nil, updated_at: nil, url: nil, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: nil}
    (stdlib) :maps.update(:slug, "hello", %Rumbl.Video{__meta__: #Ecto.Schema.Metadata<:built, "videos">, category: #Ecto.Association.NotLoaded<association :category is not loaded>, category_id: nil, description: nil, id: 1, inserted_at: nil, title: nil, updated_at: nil, url: nil, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: nil})
     (rumbl) web/models/video.ex:4: anonymous fn/2 in Rumbl.Video.__struct__/1
    (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
     (rumbl) expanding struct: Rumbl.Video.__struct__/1
             iex:1: (file)

Screenshot: image

nelsonic commented 7 years ago

Just checked and Creating videos isn't working in the UI either: image

nelsonic commented 7 years ago

Re-running mix run priv/repo/seeds.exs to create the categories meant that I can create videos: image

But still have the defimpl issue: #52

nelsonic commented 7 years ago

obviously it wasn't going to work until I added the slug to the videos model... duh!