Fixing update handling in Has_Many and Has_One relationships.

Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
Taylor Otwell
2012-04-10 11:26:03 -05:00
parent 8e988192a1
commit fda19731c5
5 changed files with 43 additions and 16 deletions

View File

@@ -29,8 +29,6 @@ class Has_Many extends Has_One_Or_Many {
foreach ($models as $attributes)
{
$attributes[$this->foreign_key()] = $this->base->get_key();
$class = get_class($this->model);
// If the "attributes" are actually an array of the related model we'll
@@ -45,6 +43,13 @@ class Has_Many extends Has_One_Or_Many {
$model = $this->fresh_model($attributes);
}
// We'll need to associate the model with its parent, so we'll set the
// foreign key on the model to the key of the parent model, making
// sure that the two models are associated in the database.
$foreign = $this->foreign_key();
$model->$foreign = $this->base->get_key();
$id = $model->get_key();
$model->exists = ( ! is_null($id) and in_array($id, $current));