diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 14a23f48b4b3..5e10cd1cde6a 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -429,7 +429,7 @@ public function getQueueableIds() */ public function getQueueableRelations() { - return $this->isNotEmpty() ? $this->first()->getRelations() : []; + return $this->isNotEmpty() ? $this->first()->getQueueableRelations() : []; } /** diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index fc08ecc3bbe0..0b8e1f26db23 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -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; } } diff --git a/tests/Integration/Queue/ModelSerializationTest.php b/tests/Integration/Queue/ModelSerializationTest.php index 4d6adfe1d03d..bc1ae2854445 100644 --- a/tests/Integration/Queue/ModelSerializationTest.php +++ b/tests/Integration/Queue/ModelSerializationTest.php @@ -146,7 +146,9 @@ 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(); @@ -154,7 +156,7 @@ public function it_reloads_relationships() 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); @@ -167,7 +169,9 @@ 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(); @@ -175,7 +179,7 @@ public function it_reloads_nested_relationships() 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); @@ -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