This commit is contained in:
yunwuxin
2017-03-03 12:22:34 +08:00
parent ff7c860a62
commit f3c4cf2b25

View File

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