initial draft of saving related models.

This commit is contained in:
Qiang Xue
2013-01-11 23:10:35 -05:00
parent 6243861138
commit ef8b092278
3 changed files with 185 additions and 41 deletions

View File

@ -253,17 +253,9 @@ class ActiveQuery extends Query
$t = strtolower($name);
if (!isset($relations[$t])) {
$getter = 'get' . $name;
if (!method_exists($model, $getter)) {
throw new Exception("Unknown relation: $name");
}
$relation = $model->$getter();
if ($relation instanceof ActiveRelation) {
$relation->primaryModel = null;
$relations[$t] = $relation;
} else {
throw new Exception("Unknown relation: $name");
}
$relation = $model->getRelation($name);
$relation->primaryModel = null;
$relations[$t] = $relation;
} else {
$relation = $relations[$t];
}