Commit a4239efa by Qiang Xue

Fixes #637.

parent b28e6b90
...@@ -1256,6 +1256,9 @@ class ActiveRecord extends Model ...@@ -1256,6 +1256,9 @@ class ActiveRecord extends Model
$relation = $this->getRelation($name); $relation = $this->getRelation($name);
if ($relation->via !== null) { if ($relation->via !== null) {
if ($this->getIsNewRecord() || $model->getIsNewRecord()) {
throw new InvalidCallException('Unable to link models: both models must NOT be newly created.');
}
if (is_array($relation->via)) { if (is_array($relation->via)) {
/** @var $viaRelation ActiveRelation */ /** @var $viaRelation ActiveRelation */
list($viaName, $viaRelation) = $relation->via; list($viaName, $viaRelation) = $relation->via;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment