1
 2  def hydrate(params, repo, schema, result_key, [{attribute, lookup_key}]) do
 3    if !params[lookup_key] ||
 4         (params[result_key] && params[result_key][attribute] == params[lookup_key]) do
 5      {:ok, params}
 6    else
 7      criteria = [{attribute, params[lookup_key]}]
 8
 9      schema
10      |> Ecto.Query.where(^criteria)
11      |> repo.one()
12      |> verify_presence(result_key, attribute, lookup_key, params)
13    end
14  end
posted Apr 6 at 22:29

0 Refactors