File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -181,17 +181,36 @@ protected function query(Query $query) {}
181181 /**
182182 * 获取查询对象
183183 *
184+ * @param array|null $scope 设置不使用的全局查询范围
184185 * @return Query
185186 */
186- public function getQuery (): Query
187+ public function getQuery (array | null $ scope = [] ): Query
187188 {
188189 $ query = $ this ->db ();
189-
190+ // 全局查询范围
191+ if (is_array ($ scope )) {
192+ $ globalScope = array_diff ($ this ->getOption ('globalScope ' , []), $ scope );
193+ $ query ->scope ($ globalScope );
194+ }
190195 // 执行扩展查询
191196 $ this ->query ($ query ->suffix ($ this ->getOption ('suffix ' )));
192197 return $ query ;
193198 }
194199
200+ /**
201+ * 设置不使用的全局查询范围.
202+ *
203+ * @param array $scope 不启用的全局查询范围
204+ *
205+ * @return Query
206+ */
207+ public static function withoutGlobalScope (?array $ scope = null ): Query
208+ {
209+ $ model = new static ();
210+
211+ return $ model ->getQuery ($ scope );
212+ }
213+
195214 public static function __callStatic ($ method , $ args )
196215 {
197216 $ model = new static ();
You can’t perform that action at this time.
0 commit comments