Commit c9c0ddf5 authored by Taylor Otwell's avatar Taylor Otwell

Fixing bugs in Eq2.

Signed-off-by: 's avatarTaylor Otwell <taylorotwell@gmail.com>
parent e857505e
<?php namespace Laravel\Database\Eloquent;
use Laravel\Database;
use Eloquent\Relationships\Has_Many_And_Belongs_To;
use Laravel\Database\Eloquent\Relationships\Has_Many_And_Belongs_To;
abstract class Model {
......@@ -320,7 +320,7 @@ abstract class Model {
*/
protected function timestamp()
{
$this->updated_at = $this->get_timestamp();
$this->updated_at = static::get_timestamp();
if ( ! $this->exists) $this->created_at = $this->updated_at;
}
......@@ -330,7 +330,7 @@ abstract class Model {
*
* @return mixed
*/
protected function get_timestamp()
protected static function get_timestamp()
{
return date('Y-m-d H:i:s');
}
......@@ -406,7 +406,7 @@ abstract class Model {
*/
public function get_attribute($key)
{
return $this->attributes[$key];
return array_get($this->attributes, $key);
}
/**
......
......@@ -76,7 +76,7 @@ class Query {
{
// 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 @@ class Query {
}
}
// 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;
}
......
......@@ -133,7 +133,7 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
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 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
public function match($relationship, &$parents, $children)
{
$foreign = 'eloquent_foreign_key';
$foreign = 'pivot_foreign_key';
foreach ($children as $key => $child)
{
......@@ -216,6 +216,20 @@ class Has_Many_And_Belongs_To extends Relationship {
}
}
/**
* 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.
*
......
<?php namespace Laravel\Database\Eloquent\Relationships; use Eloquent\Model;
<?php namespace Laravel\Database\Eloquent\Relationships;
use Laravel\Database\Eloquent\Model;
class Has_One_Or_Many extends Relationship {
......
<?php namespace Laravel\Database\Eloquent\Relationships; use Eloquent\Model, Eloquent\Query;
<?php namespace Laravel\Database\Eloquent\Relationships;
use Laravel\Database\Eloquent\Model;
use Laravel\Database\Eloquent\Query;
abstract class Relationship extends Query {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment