leafsphp / db

🗄 Leaf PHP db module
https://leafphp.dev/modules/db/
6 stars 11 forks source link

orderBy method chaining fix #13

Closed Bazowsky closed 8 months ago

Bazowsky commented 1 year ago

Description

Related Issue

mychidarko commented 11 months ago

Hi @Bazowsky can you pls give some context on what this PR is fixing

Bazowsky commented 11 months ago

Before: $db->select('users')->orderBy('registrationDate', 'asc'); (It`s ok) [query] => SELECT * FROM users ORDER BY registrationDate ASC

On first chain fails $db->select('users')->orderBy('registrationDate', 'asc')->orderBy('score', 'desc'); [query] => SELECT * FROM users ORDER BY score DESC ASC

Second $db->select('users')->orderBy('registrationDate', 'asc')->orderBy('score', 'desc')->orderBy('matches', 'desc'); [query] => SELECT * FROM users ORDER BY matches DESC DESC ASC

After: $db->select('users')->orderBy('registrationDate', 'asc') [query] => SELECT * FROM users ORDER BY registrationDate ASC

$db->select('users')->orderBy('registrationDate', 'asc')->orderBy('score', 'desc') [query] => SELECT * FROM users ORDER BY score DESC, registrationDate ASC

$db->select('users')->orderBy('registrationDate', 'asc')->orderBy('score', 'desc')->orderBy('matches', 'desc') [query] => SELECT * FROM users ORDER BY matches DESC, score DESC, registrationDate ASC

And so on...

mychidarko commented 8 months ago

Thanks for this fix ❤️