8000 [Feature] Add new relation query method to Eloquent adapter · rubinred/laravel-json-api@71f2ddd · GitHub
[go: up one dir, main page]

Skip to content

Commit 71f2ddd

Browse files
committed
[Feature] Add new relation query method to Eloquent adapter
Closes cloudcreativity#490
1 parent 98f192b commit 71f2ddd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file. This projec
99

1010
- [#586](https://github.com/cloudcreativity/laravel-json-api/pull/586) Added French translations for validation and
1111
specification compliance messages.
12+
- [#490](https://github.com/cloudcreativity/laravel-json-api/issues/490) Add `newRelationQuery()` method to Eloquent
13+
adapter.
1214

1315
### Fixed
1416
- [#576](https://github.com/cloudcreativity/laravel-json-api/issues/576) Correctly pass existing resource values to

src/Eloquent/AbstractAdapter.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function query(EncodingParametersInterface $parameters)
139139
public function queryToMany($relation, EncodingParametersInterface $parameters)
140140
{
141141
$this->applyScopes(
142-
$query = $relation->newQuery()
142+
$query = $this->newRelationQuery($relation)
143143
);
144144

145145
return $this->queryAllOrOne(
@@ -161,7 +161,7 @@ public function queryToMany($relation, EncodingParametersInterface $parameters)
161161
public function queryToOne($relation, EncodingParametersInterface $parameters)
162162
{
163163
$this->applyScopes(
164-
$query = $relation->newQuery()
164+
$query = $this->newRelationQuery($relation)
165165
);
166166

167167
return $this->queryOne(
@@ -286,6 +286,15 @@ protected function newQuery()
286286
return $builder;
287287
}
288288

289+
/**
290+
* @param Relations\BelongsToMany|Relations\HasMany|Relations\HasManyThrough|Builder $relation
291+
* @return Builder
292+
*/
293+
protected function newRelationQuery($relation)
294+
{
295+
return $relation->newQuery();
296+
}
297+
289298
/**
290299
* @param $resourceId
291300
* @return Builder
@@ -699,7 +708,7 @@ protected function getQueryParameters(EncodingParametersInterface $parameters)
699708
*/
700709
private function guessRelation()
701710
{
702-
list($one, $two, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
711+
[$one, $two, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
703712

704713
return $this->modelRelationForField($caller['function']);
705714
}

0 commit comments

Comments
 (0)
0