 
   # Build a query for fetching public contests.
   defp public_contests_query do
-    Contest
-    |> where(timetables_public: true)
-    |> preload(:host)
+    from c in Contest,
+      as: :contests,
+      where: c.timetables_public
   end
 
   # Build a query for fetching stages in display order.

      left_join: u in assoc(h, :users),
      as: :users
  end
end

  end

  def get_public_contest(id) do
    public_contests_query() |> preload(:host) |> Repo.get(id)
  end

  def get_public_contest!(id) do
    public_contests_query() |> preload(:host) |> Repo.get!(id)
  end

  @doc """
