I learning phoenix(1.3.4) by making Link Bookmarking for myself, i use it for almost a month and there is no problem with functionality. 3 days ago i updated Elixir & Erlang version and my application still fine after recompile with lot of warnings. But last night when i tried to open the profile page suddenly i got “expected at least one result but got none in query”, and I haven’t touched the application code in a 2 weeks.
Ecto.NoResultsError at GET /@1
expected at least one result but got none in query:
from l in Eltar.Topic.Link,
where: l.id == ^"1",
preload: [:user]
lib/ecto/repo/queryable.ex
def one!(repo, adapter, queryable, opts) do
case all(repo, adapter, queryable, opts) do
[one] -> one
--> [] -> raise Ecto.NoResultsError, queryable: queryable
other -> raise Ecto.MultipleResultsError, queryable: queryable, count: length(other)
end
end
DB access code:
def get_link_with_user(id) do
Link
|> preload(:user)
|> Repo.get!(id)
end
Controller code:
def profile(conn,%{"id" => id}) do
link = Topic.get_link_with_user(id)
render(conn, "profile.html", page_title: link.user.login <> " - Eltar",link: link)
end
Router:
get "/@:id", LinkController, :profile
Template:
<a href="/@<%= link.user.id %>" >
<%= link.user.login %>
</a> <%= link.inserted_at |> seconds_ago() |> time_ago_in_words() %>
How can i fix this error?