Skip to content

Commit

Permalink
Add new definition for version_query function to merge options into t…
Browse files Browse the repository at this point in the history
…he Ecto query
  • Loading branch information
dreamingechoes committed Jul 28, 2017
1 parent d4d8e40 commit 59f34c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/paper_trail/version_queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ defmodule PaperTrail.VersionQueries do
@repo.get("Elixir." <> version.item_type |> String.to_existing_atom, version.item_id)
end


defp version_query(item_type, id) do
from v in Version,
where: v.item_type == ^item_type and v.item_id == ^id
from v in Version, where: v.item_type == ^item_type and v.item_id == ^id
end
defp version_query(item_type, id, options) do
with opts <- Enum.into(options, %{}) do
version_query(item_type, id)
|> Ecto.Queryable.to_query()
|> Map.merge(opts)
end
end
end

0 comments on commit 59f34c4

Please sign in to comment.