This commit is contained in:
thinkphp
2017-03-17 19:27:45 +08:00
parent 224a9d5bb3
commit 1f0d3bd74a

View File

@@ -376,11 +376,11 @@ class BelongsToMany extends Relation
// 关联查询封装
$tableName = $this->query->getTable();
$relationFk = $this->query->getPk();
$table = $this->pivot->getTable();
$query = $this->query->field($tableName . '.*')
->field(true, false, $table, 'pivot', 'pivot__');
if (empty($this->baseQuery)) {
$table = $this->pivot->getTable();
$query->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk)
->where($condition);
}