修正关联模型 多对多save方法一处问题

This commit is contained in:
thinkphp
2016-09-21 12:08:07 +08:00
parent cbfa98341b
commit fcde43a1b0

View File

@@ -604,7 +604,8 @@ class Relation
if (is_array($data)) {
// 保存关联表数据
$model = new $this->model;
$id = $model->save($data);
$model->save($data);
$id = $model->getLastInsID();
} elseif (is_numeric($data) || is_string($data)) {
// 根据关联表主键直接写入中间表
$id = $data;
@@ -681,11 +682,14 @@ class Relation
$pk = (new $this->model)->getPk();
$throughKey = $this->throughKey;
$modelTable = $this->parent->getTable();
$result = $this->query->field($alias . '.*')->alias($alias)
$this->query->field($alias . '.*')->alias($alias)
->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey)
->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey)
->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey});
break;
case self::BELONGS_TO_MANY:
// TODO
}
$result = call_user_func_array([$this->query, $method], $args);
if ($result instanceof \think\db\Query) {