   end
 
   def show(conn, %{"id" => id}) do
-    series = Series |> Repo.get!(id) |> Repo.preload(:episodes)
+    series =
+      Series
+      |> Repo.get!(id)
+      |> Repo.preload(:episodes)
+      |> Repo.preload(:franchise)
     render(conn, "show.json", series: series)
   end
 
   def update(conn, %{"id" => id, "series" => series_params}) do
-    series = Series |> Repo.get!(id) |> Repo.preload(:episodes)
-    params = series_params |> populate |> to_map
+    series = Series |> Repo.get!(id)
+    params =
+      series_params
+      |> populate
+      |> to_map
+      |> Enum.filter(fn {_k, v} -> v != nil end)
+      |> Map.new
+
     changeset = Series.changeset(series, params)
 
     case Repo.update(changeset) do
       {:ok, series} ->
+        series =
+          series
+          |> Repo.preload(:episodes)
+          |> Repo.preload(:franchise)
+
         render(conn, "show.json", series: series)
       {:error, changeset} ->
         conn

  end

  def create(conn, %{"series" => series_params}) do
    params = series_params |> populate |> to_map
    changeset = Series.changeset(%Series{}, params)

    case Repo.insert(changeset) do
      {:ok, series} ->
        conn
        |> put_status(:created)
        |> put_resp_header("location", series_path(conn, :show, series))

  import Animu.ModelHelper
  import Animu.SeriesPopulator

  alias Animu.{Series, Episode}

  plug Guardian.Plug.EnsureAuthenticated, handler: Animu.SessionController

