Skip to content

Commit 07b6465

Browse files
authored
Merge pull request #113 from tailflow/next
v2.1.3 Release
2 parents cac23d5 + 4e7d1f3 commit 07b6465

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

src/Concerns/HandlesRelationOneToManyOperations.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ public function dissociate(Request $request, $parentKey, $relatedKey)
170170
$this->performDissociate($request, $parentEntity, $entity);
171171

172172
$entity = $this->relationQueryBuilder->buildQuery($entity::query(), $request)
173-
->with($this->relationsResolver->requestedRelations($request))->first();
173+
->with($this->relationsResolver->requestedRelations($request))->where(
174+
$this->resolveQualifiedKeyName(),
175+
$entity->{$this->keyName()}
176+
)->firstOrFail();
174177

175178
$afterHookResult = $this->afterDissociate($request, $parentEntity,$entity);
176179
if ($this->hookResponds($afterHookResult)) {

src/Concerns/HandlesRelationStandardBatchOperations.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public function batchStore(Request $request, $parentKey)
5454
Arr::get($resource, 'pivot', [])
5555
);
5656

57-
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
57+
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
58+
$this->resolveQualifiedKeyName(),
59+
$entity->{$this->keyName()}
60+
)->first();
5861
$entity->wasRecentlyCreated = true;
5962

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

171-
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
174+
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
175+
$this->resolveQualifiedKeyName(),
176+
$entity->{$this->keyName()}
177+
)->first();
172178

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

@@ -336,9 +342,10 @@ public function batchDestroy(Request $request, $parentKey)
336342
if (!$forceDeletes) {
337343
$this->performDestroy($entity);
338344
if ($softDeletes) {
339-
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->find(
340-
$entity->id
341-
);
345+
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->where(
346+
$this->resolveQualifiedKeyName(),
347+
$entity->{$this->keyName()}
348+
)->firstOrFail();
342349
}
343350
} else {
344351
$this->performForceDestroy($entity);
@@ -481,7 +488,10 @@ public function batchRestore(Request $request, $parentKey)
481488

482489
$this->performRestore($entity);
483490

484-
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
491+
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
492+
$this->resolveQualifiedKeyName(),
493+
$entity->{$this->keyName()}
494+
)->firstOrFail();
485495

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

src/Concerns/HandlesRelationStandardOperations.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ public function store(Request $request, $parentKey)
261261
$request->get('pivot', [])
262262
);
263263

264-
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
264+
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
265+
$this->resolveQualifiedKeyName(),
266+
$entity->{$this->keyName()}
267+
)->firstOrFail();
265268
$entity->wasRecentlyCreated = true;
266269

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

593-
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
596+
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
597+
$this->resolveQualifiedKeyName(),
598+
$entity->{$this->keyName()}
599+
)->firstOrFail();
594600

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

@@ -754,9 +760,10 @@ public function destroy(Request $request, $parentKey, $relatedKey = null)
754760
if (!$forceDeletes) {
755761
$this->performDestroy($entity);
756762
if ($softDeletes) {
757-
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->find(
758-
$entity->id
759-
);
763+
$entity = $this->newRelationQuery($parentEntity)->withTrashed()->with($requestedRelations)->where(
764+
$this->resolveQualifiedKeyName(),
765+
$entity->{$this->keyName()}
766+
)->firstOrFail();
760767
}
761768
} else {
762769
$this->performForceDestroy($entity);
@@ -915,7 +922,10 @@ public function restore(Request $request, $parentKey, $relatedKey = null)
915922

916923
$this->performRestore($entity);
917924

918-
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->find($entity->id);
925+
$entity = $this->newRelationQuery($parentEntity)->with($requestedRelations)->where(
926+
$this->resolveQualifiedKeyName(),
927+
$entity->{$this->keyName()}
928+
)->firstOrFail();
919929

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

0 commit comments

Comments
 (0)