Skip to content

Commit

Permalink
Merge pull request #113 from tailflow/next
Browse files Browse the repository at this point in the history
v2.1.3 Release
  • Loading branch information
alexzarbn authored Jul 10, 2021
2 parents cac23d5 + 4e7d1f3 commit 07b6465
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/Concerns/HandlesRelationOneToManyOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ public function dissociate(Request $request, $parentKey, $relatedKey)
$this->performDissociate($request, $parentEntity, $entity);

$entity = $this->relationQueryBuilder->buildQuery($entity::query(), $request)
->with($this->relationsResolver->requestedRelations($request))->first();
->with($this->relationsResolver->requestedRelations($request))->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();

$afterHookResult = $this->afterDissociate($request, $parentEntity,$entity);
if ($this->hookResponds($afterHookResult)) {
Expand Down
22 changes: 16 additions & 6 deletions src/Concerns/HandlesRelationStandardBatchOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function batchStore(Request $request, $parentKey)
Arr::get($resource, 'pivot', [])
);

$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->first();
$entity->wasRecentlyCreated = true;

$entity = $this->cleanupEntity($entity);
Expand Down Expand Up @@ -168,7 +171,10 @@ public function batchUpdate(Request $request, $parentKey)
Arr::get($resource, 'pivot', [])
);

$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->first();

$entity = $this->cleanupEntity($entity);

Expand Down Expand Up @@ -336,9 +342,10 @@ public function batchDestroy(Request $request, $parentKey)
if (!$forceDeletes) {
$this->performDestroy($entity);
if ($softDeletes) {
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->find(
$entity->id
);
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();
}
} else {
$this->performForceDestroy($entity);
Expand Down Expand Up @@ -481,7 +488,10 @@ public function batchRestore(Request $request, $parentKey)

$this->performRestore($entity);

$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();

$entity = $this->cleanupEntity($entity);

Expand Down
22 changes: 16 additions & 6 deletions src/Concerns/HandlesRelationStandardOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ public function store(Request $request, $parentKey)
$request->get('pivot', [])
);

$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();
$entity->wasRecentlyCreated = true;

$entity = $this->cleanupEntity($entity);
Expand Down Expand Up @@ -590,7 +593,10 @@ public function update(Request $request, $parentKey, $relatedKey = null)
$request->get('pivot', [])
);

$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();

$entity = $this->cleanupEntity($entity);

Expand Down Expand Up @@ -754,9 +760,10 @@ public function destroy(Request $request, $parentKey, $relatedKey = null)
if (!$forceDeletes) {
$this->performDestroy($entity);
if ($softDeletes) {
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->find(
$entity->id
);
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();
}
} else {
$this->performForceDestroy($entity);
Expand Down Expand Up @@ -915,7 +922,10 @@ public function restore(Request $request, $parentKey, $relatedKey = null)

$this->performRestore($entity);

$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
$this->resolveQualifiedKeyName(),
$entity->{$this->keyName()}
)->firstOrFail();

$entity = $this->cleanupEntity($entity);

Expand Down

0 comments on commit 07b6465

Please sign in to comment.