内核更新
This commit is contained in:
@@ -209,7 +209,9 @@ class Merge extends Model
|
||||
// 处理关联模型数据
|
||||
$data = $this->parseData($name, $this->data);
|
||||
$query = clone $db;
|
||||
$query->table($table)->strict(false)->where($this->fk, $this->data[$this->getPk()])->update($data);
|
||||
if ($query->table($table)->strict(false)->where($this->fk, $this->data[$this->getPk()])->update($data)) {
|
||||
$result = 1;
|
||||
}
|
||||
}
|
||||
// 新增回调
|
||||
$this->trigger('after_update', $this);
|
||||
|
||||
@@ -554,7 +554,7 @@ class Relation
|
||||
case self::BELONGS_TO:
|
||||
case self::HAS_MANY:
|
||||
if ($data instanceof Model) {
|
||||
$data = $data->toArray();
|
||||
$data = $data->getData();
|
||||
}
|
||||
// 保存关联表数据
|
||||
$data[$this->foreignKey] = $this->parent->{$this->localKey};
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user