File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 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
6363 {
6464 $ orders = collect ($ this ->query ->orders );
6565
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+ })
6974 ?: '' ;
7075 }
7176
Original file line number Diff line number Diff line change @@ -639,4 +639,25 @@ public function testRelationshipQueriesAreCached()
639639 $ this ->assertTrue ($ cachedResults ->diffAssoc ($ books )->isEmpty ());
640640 $ this ->assertTrue ($ liveResults ->diffAssoc ($ books )->isEmpty ());
641641 }
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+ }
642663}
You can’t perform that action at this time.
0 commit comments