-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add escape hatch for when one doesn't want
prepare_query
(#184)
- Add a way of configuring specific schemas to not get `deleted_at` clauses automatically. - Add readme example + explanation on `with_deleted` limitations
- Loading branch information
Showing
5 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,16 @@ defmodule Ecto.SoftDelete.Repo.Test do | |
end | ||
end | ||
|
||
defmodule UserWithSkipPrepareQuery do | ||
use Ecto.Schema | ||
import Ecto.SoftDelete.Schema | ||
|
||
schema "users" do | ||
field(:email, :string) | ||
soft_delete_schema(auto_exclude_from_queries?: false) | ||
end | ||
end | ||
|
||
defmodule Nondeletable do | ||
use Ecto.Schema | ||
|
||
|
@@ -130,6 +140,21 @@ defmodule Ecto.SoftDelete.Repo.Test do | |
assert Enum.member?(results, soft_deleted_user) | ||
end | ||
|
||
test "includes soft deleted records if `auto_exclude_from_queries?` is false" do | ||
user = Repo.insert!(%UserWithSkipPrepareQuery{email: "[email protected]"}) | ||
|
||
soft_deleted_user = | ||
Repo.insert!(%UserWithSkipPrepareQuery{ | ||
email: "[email protected]", | ||
deleted_at: DateTime.utc_now() | ||
}) | ||
|
||
results = UserWithSkipPrepareQuery |> Repo.all() | ||
|
||
assert Enum.member?(results, user) | ||
assert Enum.member?(results, soft_deleted_user) | ||
end | ||
|
||
test "works with schemas that don't have deleted_at column" do | ||
Repo.insert!(%Nondeletable{value: "stuff"}) | ||
results = Nondeletable |> Repo.all() | ||
|