Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/model/Pivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace think\model;

use think\helper\Str;
use think\Model;

/**
Expand All @@ -26,6 +27,11 @@ class Pivot extends Model
* @var Model
*/
public $parent;

/**
* 中间表名称.
* @var string
*/
protected $pivotName;

/**
Expand Down Expand Up @@ -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)));
}
}

Expand Down