File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
src/Illuminate/Database/Eloquent
tests/Integration/Database Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -2501,6 +2501,7 @@ public function __sleep()
25012501
25022502 $ this ->classCastCache = [];
25032503 $ this ->attributeCastCache = [];
2504+ $ this ->relationAutoloadCallback = null ;
25042505
25052506 return array_keys (get_object_vars ($ this ));
25062507 }
@@ -2515,5 +2516,9 @@ public function __wakeup()
25152516 $ this ->bootIfNotBooted ();
25162517
25172518 $ this ->initializeTraits ();
2519+
2520+ if (static ::isAutomaticallyEagerLoadingRelationships ()) {
2521+ $ this ->withRelationshipAutoloading ();
2522+ }
25182523 }
25192524}
Original file line number Diff line number Diff line change @@ -86,6 +86,31 @@ public function testRelationAutoloadForSingleModel()
8686 $ this ->assertTrue ($ post ->comments [0 ]->relationLoaded ('likes ' ));
8787 }
8888
89+ public function testRelationAutoloadWithSerialization ()
90+ {
91+ Model::automaticallyEagerLoadRelationships ();
92+
93+ $ post = Post::create ();
94+ $ comment1 = $ post ->comments ()->create (['parent_id ' => null ]);
95+ $ comment2 = $ post ->comments ()->create (['parent_id ' => $ comment1 ->id ]);
96+ $ comment2 ->likes ()->create ();
97+
98+ DB ::enableQueryLog ();
99+
100+ $ likes = [];
101+
102+ $ post = serialize ($ post );
103+ $ post = unserialize ($ post );
104+
105+ foreach ($ post ->comments as $ comment ) {
106+ $ likes = array_merge ($ likes , $ comment ->likes ->all ());
107+ }
108+
109+ $ this ->assertCount (2 , DB ::getQueryLog ());
110+
111+ Model::automaticallyEagerLoadRelationships (false );
112+ }
113+
89114 public function testRelationAutoloadVariousNestedMorphRelations ()
90115 {
91116 tap (Post::create (), function ($ post ) {
You can’t perform that action at this time.
0 commit comments