Skip to content

Commit

Permalink
cs fixwq
Browse files Browse the repository at this point in the history
  • Loading branch information
florianJacques committed Jul 2, 2024
1 parent a4ab06a commit 003fbb5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ public function refresh()
/**
* Get a serialized attribute from the model.
*
* @param string $key
* @param string $key
*
* @return mixed
*/
public function getSerializedAttribute($key)
Expand Down Expand Up @@ -807,7 +808,8 @@ public function getSerializedKey()
/**
* Determine if two models have the same ID and belong to the same table.
*
* @param \Illuminate\Database\Eloquent\Model|null $model
* @param \Illuminate\Database\Eloquent\Model|null $model
*
* @return bool
*/
public function is($model)
Expand Down
27 changes: 16 additions & 11 deletions src/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
use BackedEnum;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection as BaseCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection as BaseCollection;
use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId;

use function array_diff;
use function array_intersect;
use function array_map;
use function array_merge;
use function array_values;
use function assert;
use function collect;
use function count;
use function in_array;
use function is_numeric;
Expand Down Expand Up @@ -112,7 +115,8 @@ public function create(array $attributes = [], array $joining = [], $touch = tru
/**
* Format the sync / toggle record list so that it is keyed by ID.
*
* @param array $records
* @param array $records
*
* @return array
*/
protected function formatRecordsList($records): array
Expand All @@ -133,8 +137,9 @@ protected function formatRecordsList($records): array
*
* Each existing model is detached, and non existing ones are attached.
*
* @param mixed $ids
* @param mixed $ids
* @param bool $touch
*
* @return array
*/
public function toggle($ids, $touch = true)
Expand Down Expand Up @@ -193,22 +198,23 @@ public function toggle($ids, $touch = true)
// Once we have finished attaching or detaching the records, we will see if we
// have done any attaching or detaching, and if we have we will touch these
// relationships if they are configured to touch on any database updates.
if ($touch && (count($changes['attached']) ||
count($changes['detached']))) {

if (
$touch && (count($changes['attached']) ||
count($changes['detached']))
) {
$this->parent->touch();
$this->newRelatedQuery()->whereIn($this->relatedKey, $ids)->touch();
}

return $changes;
}


/**
* Sync the intermediate tables with a list of IDs or collection of models.
*
* @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $ids
* @param bool $detaching
* @param \Illuminate\Support\Collection|Model|array $ids
* @param bool $detaching
*
* @return array
*/
public function sync($ids, $detaching = true)
Expand Down Expand Up @@ -259,7 +265,7 @@ public function sync($ids, $detaching = true)
// ton of touch operations until we are totally done syncing the records.
foreach ($records as $id) {
// Only non strict check if exist no update s possible beacause no attributtes
if (!in_array($id, $current)) {
if (! in_array($id, $current)) {
$this->attach($id, [], false);
$changes['attached'][] = $this->castKey($id);
}
Expand Down Expand Up @@ -388,7 +394,6 @@ protected function buildDictionary(Collection $results)

foreach ($results as $result) {
foreach ($result->$foreign as $item) {

//Prevent if id is non keyable
if ($item instanceof ObjectId) {
$item = (string) $item;
Expand Down
1 change: 0 additions & 1 deletion tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ public function testBelongsToManyOid(): void
$this->assertCount(2, $explorer->planetsVisited);
$this->assertCount(2, $planet->visitors);


// Detach planets from explorer
$explorer->planetsVisited()->sync([]);

Expand Down

0 comments on commit 003fbb5

Please sign in to comment.