This commit is contained in:
Qiang Xue
2013-07-18 08:05:09 -04:00
parent b28e6b90e6
commit a4239efa7c

View File

@ -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;