Skip to content

Commit

Permalink
[11.x] Exclude laravel_through_key when replicating model, fixes #5…
Browse files Browse the repository at this point in the history
…1097 (#51098)

* exclude `laravel_through_key` when replicating model

* SylyCI fix
  • Loading branch information
Florian Stascheck authored Apr 17, 2024
1 parent 0dde4f8 commit 4e3de10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ public function replicate(?array $except = null)
$this->getCreatedAtColumn(),
$this->getUpdatedAtColumn(),
...$this->uniqueIds(),
'laravel_through_key',
]));

$attributes = Arr::except(
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Database/EloquentHasManyThroughTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@ public function testUpdateOrCreateAffectingWrongModelsRegression()
// $jane should not be updated, because it belongs to a different user altogether.
$this->assertSame('jane-slug', $jane->fresh()->slug);
}

public function testCanReplicateModelLoadedThroughHasManyThrough()
{
$team = Team::create();
$user = User::create(['team_id' => $team->id, 'name' => 'John']);
Article::create(['user_id' => $user->id, 'title' => 'John\'s new has-many-through-article']);

$article = $team->articles()->first();

$this->assertInstanceOf(Article::class, $article);

$newArticle = $article->replicate();
$newArticle->title .= ' v2';
$newArticle->save();
}
}

class User extends Model
Expand Down

0 comments on commit 4e3de10

Please sign in to comment.