This commit is contained in:
thinkphp
2017-03-17 19:42:23 +08:00
parent 1f0d3bd74a
commit 8c79c435f5

View File

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