From 86fce099b36d2a8f73e5cf0c9aee48b35ae3e881 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 26 Apr 2012 11:25:47 -0500 Subject: [PATCH] Fixed belongs_to primary key bug. --- laravel/database/eloquent/model.php | 4 ++++ laravel/database/eloquent/relationships/belongs_to.php | 2 +- laravel/documentation/changes.md | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 5cf9f7b44..c022b682b 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -390,6 +390,8 @@ abstract class Model { $query = $this->query()->where(static::$key, '=', $this->get_key()); $result = $query->update($this->get_dirty()) === 1; + + if ($result) $this->fire_event('updated'); } // If the model does not exist, we will insert the record and retrieve the last @@ -402,6 +404,8 @@ abstract class Model { $this->set_key($id); $this->exists = $result = is_numeric($this->get_key()); + + if ($result) $this->fire_event('created'); } // After the model has been "saved", we will set the original attributes to diff --git a/laravel/database/eloquent/relationships/belongs_to.php b/laravel/database/eloquent/relationships/belongs_to.php index 404632216..6ec8acdf3 100644 --- a/laravel/database/eloquent/relationships/belongs_to.php +++ b/laravel/database/eloquent/relationships/belongs_to.php @@ -32,7 +32,7 @@ class Belongs_To extends Relationship { */ protected function constrain() { - $this->table->where($this->base->key(), '=', $this->foreign_value()); + $this->table->where($this->model->key(), '=', $this->foreign_value()); } /** diff --git a/laravel/documentation/changes.md b/laravel/documentation/changes.md index 92ea4e120..a6caf5754 100644 --- a/laravel/documentation/changes.md +++ b/laravel/documentation/changes.md @@ -61,7 +61,7 @@ - `Schema::drop` now accepts `$connection` as second parameter. - Added `Input::merge` method. - Added `Input::replace` method. -- Added `eloquent.saved`, `eloquent.saving`, `eloquent.deleting`, and `eloquent.deleted` events to Eloquent models. +- Added saving, saved, updating, creating, deleting, and deleted events to Eloquent. ## Upgrading From 3.1