8000 revert eloquent back to 3.2.3 · laravel/laravel@1203473 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1203473

Browse files
committed
revert eloquent back to 3.2.3
1 parent e8119f8 commit 1203473

File tree

5 files changed

+22
-51
lines changed

5 files changed

+22
-51
lines changed

laravel/database/eloquent/model.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,7 @@ public static function all()
255255
*/
256256
public function _with($includes)
257257
{
258-
$includes = (array) $includes;
259-
260-
$this->includes = array();
261-
262-
foreach ($includes as $relationship => $constraints)
263-
{
264-
// When eager loading relationships, constraints may be set on the eager
265-
// load definition; however, is none are set, we need to swap the key
266-
// and the value of the array since there are no constraints.
267-
if (is_numeric($relationship))
268-
{
269-
list($relationship, $constraints) = array($constraints, null);
270-
}
271-
272-
$this->includes[$relationship] = $constraints;
273-
}
258+
$this->includes = (array) $includes;
274259

275260
return $this;
276261
}
@@ -533,7 +518,7 @@ public function get_dirty()
533518

534519
foreach ($this->attributes as $key => $value)
535520
{
536-
if ( ! array_key_exists($key, $this->original) or $value !== $this->original[$key])
521+
if ( ! isset($this->original[$key]) or $value !== $this->original[$key])
537522
{
538523
$dirty[$key] = $value;
539524
}
@@ -567,7 +552,6 @@ public function set_key($value)
567552
* Get a given attribute from the model.
568553
*
569554
* @param string $key
570-
* @return mixed
571555
*/
572556
public function get_attribute($key)
573557
{
@@ -723,7 +707,7 @@ public function __isset($key)
723707
{
724708
foreach (array('attributes', 'relationships') as $source)
725709
{
726-
if (array_key_exists($key, $this->$source)) return !is_null($this->$source[$key]);
710+
if (array_key_exists($key, $this->$source)) return true;
727711
}
728712

729713
if (method_exists($this, $key)) return true;
@@ -754,7 +738,7 @@ public function __call($method, $parameters)
754738
{
755739
$meta = array('key', 'table', 'connection', 'sequence', 'per_page', 'timestamps');
756740

757-
// If the method is actually the name of a static property on the model, we'll
741+
// If the method is actually the name of a static property on the model we'll
758742
// return the value of the static property. This makes it convenient for
759743
// relationships to access these values off of the instances.
760744
if (in_array($method, $meta))
@@ -764,7 +748,7 @@ public function __call($method, $parameters)
764748

765749
$underscored = array('with', 'find');
766750

767-
// Some methods need to be accessed both statically and non-statically so we'll
751+
// Some methods need to be accessed both staticly and non-staticly so we'll
768752
// keep underscored methods of those methods and intercept calls to them
769753
// here so they can be called either way on the model instance.
770754
if (in_array($method, $underscored))

laravel/database/eloquent/relationships/belongs_to.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ public function eagerly_constrain($results)
7979
/**
8080
* Match eagerly loaded child models to their parent models.
8181
*
82-
* @param string $relationship
83-
* @param array $children
84-
* @param array $parents
82+
* @param array $children
83+
* @param array $parents
8584
* @return void
8685
*/
8786
public function match($relationship, &$children, $parents)

laravel/database/eloquent/relationships/has_many.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ public function initialize(&$parents, $relationship)
8383
/**
8484
* Match eagerly loaded child models to their parent models.
8585
*
86-
* @param string $relationship
87-
* @param array $parents
88-
* @param array $children
86+
* @param array $parents
87+
* @param array $children
8988
* @return void
9089
*/
9190
public function match($relationship, &$parents, $children)

laravel/database/eloquent/relationships/has_many_and_belongs_to.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct($model, $associated, $table, $foreign, $other)
4444
$this->joining = $table ?: $this->joining($model, $associated);
4545

4646
// If the Pivot table is timestamped, we'll set the timestamp columns to be
47-
// fetched when the pivot table models are fetched by the developer, or else
47+
// fetched when the pivot table models are fetched by the developer else
4848
// the ID will be the only "extra" column fetched in by default.
4949
if (Pivot::$timestamps)
5050
{
@@ -61,8 +61,6 @@ public function __construct($model, $associated, $table, $foreign, $other)
6161
*
6262
* By default, the name is the models sorted and joined with underscores.
6363
*
64-
* @param Model $model
65-
* @param string $associated
6664
* @return string
6765
*/
6866
protected function joining($model, $associated)
@@ -88,7 +86,7 @@ public function results()
8886
* Insert a new record into the joining table of the association.
8987
*
9088
* @param int $id
91-
* @param array $attributes
89+
* @param array $joining
9290
* @return bool
9391
*/
9492
public function attach($id, $attributes = array())
@@ -133,7 +131,7 @@ public function sync($ids)
133131
}
134132

135133
// Next we will take the difference of the current and given IDs and detach
136-
// all of the entities that exist in the current array but are not in
134+
// all of the entities that exists in the current array but are not in
137135
// the array of IDs given to the method, finishing the sync.
138136
$detach = array_diff($current, $ids);
139137

@@ -319,30 +317,22 @@ public function eagerly_constrain($results)
319317
/**
320318
* Match eagerly loaded child models to their parent models.
321319
*
322-
* @param string $relationship
323-
* @param array $parents
324-
* @param array $children
320+
* @param array $parents
321+
* @param array $children
325322
* @return void
326323
*/
327324
public function match($relationship, &$parents, $children)
328325
{
329326
$foreign = $this->foreign_key();
330327

331-
$dictionary = array();
332-
333-
foreach ($children as $child)
334-
{
335-
$dictionary[$child->pivot->$foreign][] = $child;
336-
}
337-
338328
foreach ($parents as &$parent)
339329
{
340-
$parent_key = $parent->get_key();
341-
342-
if (isset($dictionary[$parent_key]))
330+
$matching = array_filter($children, function($v) use (&$parent, $foreign)
343331
{
344-
$parent->relationships[$relationship] = $dictionary[$parent_key];
345-
}
332+
return $v->pivot->$foreign == $parent->get_key();
333+
});
334+
335+
$parent->relationships[$relationship] = array_values($matching);
346336
}
347337
}
348338

@@ -386,7 +376,7 @@ protected function hydrate_pivot(&$results)
386376
/**
387377
* Set the columns on the joining table that should be fetched.
388378
*
389-
* @param array $columns
379+
* @param array $column
390380
* @return Relationship
391381
*/
392382
public function with($columns)

laravel/database/eloquent/relationships/has_one.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public function initialize(&$parents, $relationship)
3030
/**
3131
* Match eagerly loaded child models to their parent models.
3232
*
33-
* @param string $relationship
34-
* @param array $parents
35-
* @param array $children
33+
* @param array $parents
34+
* @param array $children
3635
* @return void
3736
*/
3837
public function match($relationship, &$parents, $children)

0 commit comments

Comments
 (0)
0