Skip to content

Commit

Permalink
fix BelongsToMany pivot relation wakeup
Browse files Browse the repository at this point in the history
fixes from StyleCI
  • Loading branch information
rodrigopedra committed Feb 8, 2018
1 parent b4a37ae commit 0c9beda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function getQueueableIds()
*/
public function getQueueableRelations()
{
return $this->isNotEmpty() ? $this->first()->getRelations() : [];
return $this->isNotEmpty() ? $this->first()->getQueueableRelations() : [];
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,13 @@ public function getQueueableRelations()
$relations = [];

foreach ($this->getRelations() as $key => $relation) {
$relations[] = $key;
if (method_exists($this, $key)) {
$relations[] = $key;
}

if ($relation instanceof QueueableCollection) {
foreach ($relation->getQueueableRelations() as $collectionKey => $collectionValue) {
$relations[] = $key.'.'.$collectionKey;
foreach ($relation->getQueueableRelations() as $collectionValue) {
$relations[] = $key.'.'.$collectionValue;
}
}

Expand Down
17 changes: 13 additions & 4 deletions tests/Integration/Queue/ModelSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,17 @@ public function it_fails_if_models_on_multi_connections()
*/
public function it_reloads_relationships()
{
$order = Order::create();
$order = tap(Order::create(), function (Order $order) {
$order->wasRecentlyCreated = false;
});

$product1 = Product::create();
$product2 = Product::create();

Line::create(['order_id' => $order->id, 'product_id' => $product1->id]);
Line::create(['order_id' => $order->id, 'product_id' => $product2->id]);

$order->load('line', 'lines');
$order->load('line', 'lines', 'products');

$serialized = serialize(new ModelRelationSerializationTestClass($order));
$unSerialized = unserialize($serialized);
Expand All @@ -167,15 +169,17 @@ public function it_reloads_relationships()
*/
public function it_reloads_nested_relationships()
{
$order = Order::create();
$order = tap(Order::create(), function (Order $order) {
$order->wasRecentlyCreated = false;
});

$product1 = Product::create();
$product2 = Product::create();

Line::create(['order_id' => $order->id, 'product_id' => $product1->id]);
Line::create(['order_id' => $order->id, 'product_id' => $product2->id]);

$order->load('line.product', 'lines', 'lines.product');
$order->load('line.product', 'lines', 'lines.product', 'products');

$nestedSerialized = serialize(new ModelRelationSerializationTestClass($order));
$nestedUnSerialized = unserialize($nestedSerialized);
Expand Down Expand Up @@ -215,6 +219,11 @@ public function lines()
{
return $this->hasMany(Line::class);
}

public function products()
{
return $this->belongsToMany(Product::class, 'lines');
}
}

class Line extends Model
Expand Down

0 comments on commit 0c9beda

Please sign in to comment.