diff --git a/src/model/Pivot.php b/src/model/Pivot.php index 44cf2243..c77903c5 100644 --- a/src/model/Pivot.php +++ b/src/model/Pivot.php @@ -13,6 +13,7 @@ namespace think\model; +use think\helper\Str; use think\Model; /** @@ -26,6 +27,11 @@ class Pivot extends Model * @var Model */ public $parent; + + /** + * 中间表名称. + * @var string + */ protected $pivotName; /** @@ -56,8 +62,8 @@ public function __construct(array $data = [], ?Model $parent = null, string $tab */ protected function init() { - if (is_null($this->getOption('name'))) { - $this->setOption('name', $this->pivotName); + if (null === $this->getOption('name')) { + $this->setOption('name', $this->pivotName ?: Str::snake(class_basename(static::class))); } }