File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -81,11 +81,37 @@ defmodule Ecto.SoftDelete.Repo do
8181 if has_include_deleted_at_clause? ( query ) || opts [ :with_deleted ] || ! soft_deletable? ( query ) do
8282 { query , opts }
8383 else
84- query = from ( x in query , where: is_nil ( x . deleted_at ) )
84+ query = filter_soft_deleted ( query )
8585 { query , opts }
8686 end
8787 end
8888
89+ # We need to check the entire query and apply filtering
90+ # where appropriate. So, we recurse the query here and
91+ # rebuild it with filtering where appropriate. This
92+ # currently only considers the source and does not handle
93+ # things like joins...
94+ defp filter_soft_deleted ( % Ecto.Query { from: % { source: { _schema , _module } } } = query ) do
95+ if Ecto.SoftDelete.Query . soft_deletable? ( query ) do
96+ from ( x in query , where: is_nil ( x . deleted_at ) )
97+ else
98+ query
99+ end
100+ end
101+
102+ defp filter_soft_deleted ( % Ecto.SubQuery { query: query } = sub ) do
103+ if Ecto.SoftDelete.Query . soft_deletable? ( query ) do
104+ from ( x in query , where: is_nil ( x . deleted_at ) ) |> subquery ( )
105+ else
106+ sub
107+ end
108+ end
109+
110+ defp filter_soft_deleted ( % Ecto.Query { from: from } = query ) do
111+ updated_from = % { from | source: filter_soft_deleted ( from . source ) }
112+ % { query | from: updated_from }
113+ end
114+
89115 # Checks the query to see if it contains a where not is_nil(deleted_at)
90116 # if it does, we want to be sure that we don't exclude soft deleted records
91117 defp has_include_deleted_at_clause? ( % Ecto.Query { wheres: wheres } ) do
You can’t perform that action at this time.
0 commit comments