Fixing bugs in Eq2.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
parent
e857505e35
commit
c9c0ddf569
|
@ -1,7 +1,7 @@
|
||||||
<?php namespace Laravel\Database\Eloquent;
|
<?php namespace Laravel\Database\Eloquent;
|
||||||
|
|
||||||
use Laravel\Database;
|
use Laravel\Database;
|
||||||
use Eloquent\Relationships\Has_Many_And_Belongs_To;
|
use Laravel\Database\Eloquent\Relationships\Has_Many_And_Belongs_To;
|
||||||
|
|
||||||
abstract class Model {
|
abstract class Model {
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ public function save()
|
||||||
*/
|
*/
|
||||||
protected function timestamp()
|
protected function timestamp()
|
||||||
{
|
{
|
||||||
$this->updated_at = $this->get_timestamp();
|
$this->updated_at = static::get_timestamp();
|
||||||
|
|
||||||
if ( ! $this->exists) $this->created_at = $this->updated_at;
|
if ( ! $this->exists) $this->created_at = $this->updated_at;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ protected function timestamp()
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function get_timestamp()
|
protected static function get_timestamp()
|
||||||
{
|
{
|
||||||
return date('Y-m-d H:i:s');
|
return date('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ public function set_key($value)
|
||||||
*/
|
*/
|
||||||
public function get_attribute($key)
|
public function get_attribute($key)
|
||||||
{
|
{
|
||||||
return $this->attributes[$key];
|
return array_get($this->attributes, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -76,7 +76,7 @@ public function get($columns = array('*'), $include = true)
|
||||||
{
|
{
|
||||||
// If the relationship is nested, we will skip laoding it here and let
|
// 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
|
// 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, '.'))
|
if (str_contains($relationship, '.'))
|
||||||
{
|
{
|
||||||
continue;
|
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;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ protected function constrain()
|
||||||
*/
|
*/
|
||||||
protected function set_select($foreign)
|
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));
|
$this->table->select(array($this->model->table().'.*', $foreign));
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ public function eagerly_constrain($results)
|
||||||
*/
|
*/
|
||||||
public function match($relationship, &$parents, $children)
|
public function match($relationship, &$parents, $children)
|
||||||
{
|
{
|
||||||
$foreign = 'eloquent_foreign_key';
|
$foreign = 'pivot_foreign_key';
|
||||||
|
|
||||||
foreach ($children as $key => $child)
|
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.
|
* Get the other or associated key for the relationship.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<?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 {
|
class Has_One_Or_Many extends Relationship {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?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 {
|
abstract class Relationship extends Query {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue