joeljuca / swiss_schema

A Swiss Army knife for your Ecto schemas
https://hex.pm/packages/swiss_schema
Apache License 2.0
26 stars 4 forks source link

`c:get_by/2` crashes when multiple entries are returned #9

Closed joeljuca closed 2 months ago

joeljuca commented 8 months ago

Ecto.Repo's get_by/3 expects a set of clauses that will return exactly one entry from the repository. If multiple results are returned, it throws Ecto.MultipleResultsError.

iex> User.get_by is_active: true
# ** (Ecto.MultipleResultsError) expected at most one result but got 2 in query

SwissSchema's get_by/2 might be better off with a {:error, :some_atom_error}, which fits better with the tuple-based expected format for errors.