diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 32d3933c..bc60dc1f 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -1,7 +1,7 @@ updated_at = $this->get_timestamp(); + $this->updated_at = static::get_timestamp(); if ( ! $this->exists) $this->created_at = $this->updated_at; } @@ -330,7 +330,7 @@ protected function timestamp() * * @return mixed */ - protected function get_timestamp() + protected static function get_timestamp() { return date('Y-m-d H:i:s'); } @@ -406,7 +406,7 @@ public function set_key($value) */ public function get_attribute($key) { - return $this->attributes[$key]; + return array_get($this->attributes, $key); } /** diff --git a/laravel/database/eloquent/query.php b/laravel/database/eloquent/query.php index f590ad9e..9a248472 100644 --- a/laravel/database/eloquent/query.php +++ b/laravel/database/eloquent/query.php @@ -76,7 +76,7 @@ public function get($columns = array('*'), $include = true) { // If the relationship is nested, we will skip laoding it here and let // the load method parse and set the nested eager loads on the right - // relationship when it is getting ready to eager laod it. + // relationship when it is getting ready to eager laod. if (str_contains($relationship, '.')) { continue; @@ -86,6 +86,14 @@ public function get($columns = array('*'), $include = true) } } + // The many to many relationships may have pivot table column on them + // so we will call the "clean" method on the relationship to remove + // any pivot columns that are on the model. + if ($this instanceof Relationships\Has_Many_And_Belongs_To) + { + $this->clean($results); + } + return $results; } diff --git a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php index 32ac5e69..da046add 100644 --- a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php +++ b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php @@ -133,7 +133,7 @@ protected function constrain() */ protected function set_select($foreign) { - $foreign = $this->joining.'.'.$foreign.' as eloquent_foreign_key'; + $foreign = $this->joining.'.'.$foreign.' as pivot_foreign_key'; $this->table->select(array($this->model->table().'.*', $foreign)); @@ -201,7 +201,7 @@ public function eagerly_constrain($results) */ public function match($relationship, &$parents, $children) { - $foreign = 'eloquent_foreign_key'; + $foreign = 'pivot_foreign_key'; foreach ($children as $key => $child) { @@ -216,6 +216,20 @@ public function match($relationship, &$parents, $children) } } + /** + * Clean-up any pivot columns that are on the results. + * + * @param array $results + * @return void + */ + protected function clean(&$results) + { + foreach ($results as &$result) + { + + } + } + /** * Get the other or associated key for the relationship. * diff --git a/laravel/database/eloquent/relationships/has_one_or_many.php b/laravel/database/eloquent/relationships/has_one_or_many.php index a64d2bdf..211eb7db 100644 --- a/laravel/database/eloquent/relationships/has_one_or_many.php +++ b/laravel/database/eloquent/relationships/has_one_or_many.php @@ -1,4 +1,6 @@ -