Skip to content

Order By Rand() error #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RibesAlexandre opened this issue Dec 5, 2017 · 3 comments
Closed

Order By Rand() error #35

RibesAlexandre opened this issue Dec 5, 2017 · 3 comments
Assignees
Labels

Comments

@RibesAlexandre
Copy link

RibesAlexandre commented Dec 5, 2017

Issue

Undefined index Column

Environment

Laravel Version: 5.5.23
Laravel Model Caching Package Version: 0.2.9
PHP Version: 7.0.26
Homestead Version: none
Operating System & Version: name x.y.z

When I use orderByRaw('RAND()') in a model, I get These error. The simple solution is to test if the key exists.

Stack Trace

// vendor/genealabs/laravel-model-caching/src/CacheKey.php
protected function getOrderByClauses() : string
    {
        $orders = collect($this->query->orders);
 
        return $orders->reduce(function($carry, $order){
            return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
        })
        ?: '';
    }

Solution :

protected function getOrderByClauses() : string
    {
        $orders = collect($this->query->orders);

        return $orders->reduce(function($carry, $order){
            return $carry . '_orderBy_' . (isset($order['column']) ? $order['column'] : '') . '_' . (isset($order['direction']) ? $order['direction'] : '');
        })
        ?: '';
    }
@mikebronner mikebronner self-assigned this Dec 5, 2017
@mikebronner mikebronner added the bug label Dec 5, 2017
@mikebronner
Copy link
Owner

Thanks for reporting this! I will get this updated ASAP.

@mikebronner
Copy link
Owner

Just pushed 0.2.10 ... give that a try, please let me know how it goes. :) Thanks again!

@RibesAlexandre
Copy link
Author

Thanks a lot ! It works perfectly =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants