File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ JSON parameters (keys):
5757- ` offset ` - will return a subset of results starting from a point given. This parameter ** MUST**
5858be used together with `` limit `` parameter.
5959- ` count ` - will return record count.
60- - ` soft_deleted ` - will include soft deleted models in search results
60+ - ` soft_deleted ` - will include soft deleted models in search results.
61+ - ` doesnt_have_relations ` - will only return entries that don't have any of the specified relations.
6162
6263### Search
6364
@@ -357,6 +358,24 @@ with ``soft_deleted``:
357358}
358359```
359360
361+ ### Doesn't have relations
362+
363+ In case you want to only find entries without a specified relation, you can do so with `` doesnt_have_relations `` key:
364+
365+ ```
366+ {
367+ "doesnt_have_relations": "containers"
368+ }
369+ ```
370+
371+ If you want to specify multiple relations, you can do so in the following way:
372+
373+ ```
374+ {
375+ "doesnt_have_relations": ["containers", "addresses"]
376+ }
377+ ```
378+
360379## Top level logical operators
361380
362381Additionally, it is possible to group search clauses by top-level logical operator.
Original file line number Diff line number Diff line change 11<?php
22
33use Asseco \JsonQueryBuilder \RequestParameters \CountParameter ;
4+ use Asseco \JsonQueryBuilder \RequestParameters \DoesntHaveRelationsParameter ;
45use Asseco \JsonQueryBuilder \RequestParameters \GroupByParameter ;
56use Asseco \JsonQueryBuilder \RequestParameters \LimitParameter ;
67use Asseco \JsonQueryBuilder \RequestParameters \OffsetParameter ;
3435 CountParameter::class,
3536 GroupByParameter::class,
3637 SoftDeletedParameter::class,
38+ DoesntHaveRelationsParameter::class,
3739 ],
3840
3941 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Asseco \JsonQueryBuilder \RequestParameters ;
6+
7+ use Asseco \JsonQueryBuilder \Exceptions \JsonQueryBuilderException ;
8+ use Illuminate \Support \Str ;
9+
10+ class DoesntHaveRelationsParameter extends AbstractParameter
11+ {
12+ public static function getParameterName (): string
13+ {
14+ return 'doesnt_have_relations ' ;
15+ }
16+
17+ protected function appendQuery (): void
18+ {
19+ foreach ($ this ->arguments as $ argument ) {
20+ if (is_string ($ argument )) {
21+ $ this ->builder ->doesntHave (Str::camel ($ argument ));
22+ continue ;
23+ }
24+
25+ throw new JsonQueryBuilderException ('Wrong relation parameters provided. ' );
26+ }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments