@@ -7,15 +7,15 @@ export default function Query(
77 query : typeof BaseQuery
88) : void {
99 /**
10- * Determine if trashed records should be filtered exclusively.
11- * true = only trashed records
12- * false = include trashed records
13- * null = exclude trashed records
10+ * Determine if soft deleted models should be filtered exclusively.
11+ * true = only soft deletes
12+ * false = include soft deletes
13+ * null = exclude soft deletes
1414 */
1515 query . prototype . softDeletesFilter = null
1616
1717 /**
18- * Constraint includes trashed records .
18+ * Constraint includes soft deleted models .
1919 */
2020 query . prototype . withTrashed = function ( ) {
2121 this . softDeletesFilter = false
@@ -24,7 +24,7 @@ export default function Query(
2424 }
2525
2626 /**
27- * Constraint restricts to only trashed records .
27+ * Constraint restricts to only soft deleted models .
2828 */
2929 query . prototype . onlyTrashed = function ( ) {
3030 this . softDeletesFilter = true
@@ -48,28 +48,28 @@ export default function Query(
4848 }
4949
5050 /**
51- * Process the record(s) to be trashed.
52- * The method expects the condition to be a single or collection of a primary
53- * key, a single or collection of a composite key, or a expression closure.
51+ * Process the model(s) to be soft deleted.
5452 */
5553 query . prototype . softDelete = function ( condition : any ) {
56- const config = context . createConfig ( this . model . softDeleteConfig )
54+ const { key, flagName, mutator } = context . createConfig (
55+ this . model . softDeleteConfig
56+ )
5757
5858 let value = Date . now ( )
5959
60- value = typeof config . mutator === 'function' ? config . mutator ( value ) : value
60+ value = typeof mutator === 'function' ? mutator ( value ) : value
6161
6262 const data = {
63- [ config . key ] : value ,
64- [ config . flagName ] : true
63+ [ key ] : value ,
64+ [ flagName ] : true
6565 }
6666
6767 if ( Array . isArray ( condition ) ) {
6868 // Array of primary keys
6969 if ( ! this . model . isCompositePrimaryKey ( ) ) {
7070 return this . model . update ( {
7171 data,
72- where : ( r ) => condition . includes ( r [ r . $primaryKey ( ) ] )
72+ where : ( record ) => condition . includes ( record [ record . $primaryKey ( ) ] )
7373 } )
7474 }
7575
@@ -86,21 +86,20 @@ export default function Query(
8686 }
8787 }
8888
89- return this . model . update ( {
90- data,
91- where : condition as any
92- } )
89+ return this . model . update ( { data, where : condition } )
9390 }
9491
9592 /**
96- * Fetch all trashed records from the store.
93+ * Fetch all soft deletes from the store.
9794 */
9895 query . prototype . allTrashed = function ( ) {
99- return this . onlyTrashed ( ) . get ( )
96+ return this . newQuery ( )
97+ . onlyTrashed ( )
98+ . get ( )
10099 }
101100
102101 /**
103- * Fetch all trashed records from the store and group by entity.
102+ * Fetch all soft deletes from the store and group by entity.
104103 */
105104 query . allTrashed = function ( store ) {
106105 const database = store . $db ( )
@@ -113,25 +112,25 @@ export default function Query(
113112 }
114113
115114 /**
116- * Global select hook prevents trashed records from being selected unless
115+ * Global select hook prevents soft deleted models from being selected unless
117116 * queries are explicity chained with `withTrashed` or `onlyTrashed`.
118117 */
119118 query . on ( 'beforeSelect' , function < T extends BaseQuery > (
120119 this : T ,
121120 models : Data . Collection
122121 ) {
123122 return models . filter ( ( model ) => {
124- // Only trashed records
123+ // Only soft deletes
125124 if ( this . softDeletesFilter === true ) {
126125 return model . $trashed ( )
127126 }
128127
129- // Include trashed records
128+ // Include soft deletes
130129 if ( this . softDeletesFilter === false ) {
131130 return models
132131 }
133132
134- // Exclude trashed records
133+ // Exclude soft deletes
135134 return ! model . $trashed ( )
136135 } )
137136 } )
0 commit comments