File tree 2 files changed +29
-3
lines changed
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,14 @@ protected function getOrderByClauses() : string
63
63
{
64
64
$ orders = collect ($ this ->query ->orders );
65
65
66
- return $ orders ->reduce (function ($ carry , $ order ) {
67
- return $ carry . '_orderBy_ ' . $ order ['column ' ] . '_ ' . $ order ['direction ' ];
68
- })
66
+ return $ orders
67
+ ->reduce (function ($ carry , $ order ) {
68
+ if ($ order ['type ' ] === 'Raw ' ) {
69
+ return $ carry . '_orderByRaw_ ' . str_slug ($ order ['sql ' ]);
70
+ }
71
+
72
+ return $ carry . '_orderBy_ ' . $ order ['column ' ] . '_ ' . $ order ['direction ' ];
73
+ })
69
74
?: '' ;
70
75
}
71
76
Original file line number Diff line number Diff line change @@ -639,4 +639,25 @@ public function testRelationshipQueriesAreCached()
639
639
$ this ->assertTrue ($ cachedResults ->diffAssoc ($ books )->isEmpty ());
640
640
$ this ->assertTrue ($ liveResults ->diffAssoc ($ books )->isEmpty ());
641
641
}
642
+
643
+ public function testRawOrderByWithoutColumnReference ()
644
+ {
645
+ $ authors = (new Author )
646
+ ->orderByRaw ('DATE() ' )
647
+ ->get ();
648
+
649
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor_orderByRaw_date ' ;
650
+ $ tags = ['genealabslaravelmodelcachingtestsfixturesauthor ' ];
651
+
652
+ $ cachedResults = cache ()
653
+ ->tags ($ tags )
654
+ ->get ($ key );
655
+
656
+ $ liveResults = (new UncachedAuthor )
657
+ ->orderByRaw ('DATE() ' )
658
+ ->get ();
659
+
660
+ $ this ->assertTrue ($ cachedResults ->diffAssoc ($ authors )->isEmpty ());
661
+ $ this ->assertTrue ($ liveResults ->diffAssoc ($ authors )->isEmpty ());
662
+ }
642
663
}
You can’t perform that action at this time.
0 commit comments