Fixing update handling in Has_Many and Has_One relationships.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user