Skip to content

Commit 6ac2f35

Browse files
authored
[13.x] Generate plural morph pivot table name (#56832)
* Update test to use 'MorphPivot' model for pivot * Only generate a singular table name for non-morph pivots
1 parent e64c715 commit 6ac2f35

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Database\Eloquent\Relations\Concerns;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\MorphPivot;
67
use Illuminate\Support\Str;
78

89
trait AsPivot
@@ -166,13 +167,13 @@ protected function getDeleteQuery()
166167
*/
167168
public function getTable()
168169
{
169-
if (! isset($this->table)) {
170+
if (! isset($this->table) && (! $this instanceof MorphPivot)) {
170171
$this->setTable(str_replace(
171172
'\\', '', Str::snake(Str::singular(class_basename($this)))
172173
));
173174
}
174175

175-
return $this->table;
176+
return parent::getTable();
176177
}
177178

178179
/**

tests/Database/DatabaseEloquentIntegrationTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,10 +2834,14 @@ public function parentPost()
28342834

28352835
public function tags()
28362836
{
2837-
return $this->morphToMany(EloquentTestTag::class, 'taggable', null, null, 'tag_id')->withPivot('taxonomy');
2837+
return $this->morphToMany(EloquentTestTag::class, 'taggable', Taggable::class, null, 'tag_id')->withPivot('taxonomy');
28382838
}
28392839
}
28402840

2841+
class Taggable extends MorphPivot
2842+
{
2843+
}
2844+
28412845
class EloquentTestTag extends Eloquent
28422846
{
28432847
protected $table = 'tags';

0 commit comments

Comments
 (0)