Cast_assoc is null?

Sweet it’s working, holy shit. I have so much more to learn. It’s failing

 def show(conn, %{"id" => id}) do
    flux = Magnets.get_flux!(id)
    render(conn, "show.html", flux: flux)
  end 

flux_controller.ex:35: MagnifyWeb.FluxController.show/2

which is this part flux = Magnets.get_flux!(id)

Happing after the create which than renders the single view template via show

Sweet it’s working, holy shit. I have so much more to learn. It’s failing

So is it working or is it failing? I don’t see any mention of :magnets association in

 def show(conn, %{"id" => id}) do
    flux = Magnets.get_flux!(id)
    render(conn, "show.html", flux: flux)
  end 

Maybe the problem is in the "show.html.eex" template. Or maybe check your magnets schema again … Maybe there is a typo? Like :magents instead of :magnets judging by

schema Magnify.Magnets.Flux does not have association :magents

Working, amazing thanks for the all help had an issue with the following old code I trying to get working

def get_flux!(id)
      do Repo.get!(Flux, id)
          |> Repo.preload(:magents)
      end

just need to remove |> Repo.preload(:magents)

working with this

def get_flux!(id)
      do Repo.get!(Flux, id)
  end

There’s a type in Repo.preload. :magents instead of :magnets.

Well do I still need repo preload?

I don’t know, depends on whether you render magnets in the "show.html.eex" template.

 def show(conn, %{"id" => id}) do
    flux = Magnets.get_flux!(id)
    render(conn, "show.html", flux: flux)
  end 

Yes I will need to that is my next stop no idea to to reference it

I have this - <%= @flux.description %>

but not sure how you render the magnets

Then, yes, you do need to preload :magnets:

def get_flux!(id) do
  Flux
  |> Repo.get!(id)
  |> Repo.preload(:magnets)
end

so that you have access to them in the template

<%= @flux.description %>
<%= Enum.map(@flux.magnets, fn magnet -> %>
  <p><%= magnet.name %></p>
<% end) %>
1 Like

Amazing all working