Skip to content
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

error on count() or sum('column') #66

Closed
jetwes opened this issue Feb 12, 2018 · 13 comments
Closed

error on count() or sum('column') #66

jetwes opened this issue Feb 12, 2018 · 13 comments
Assignees
Labels

Comments

@jetwes
Copy link

jetwes commented Feb 12, 2018

Issue

*Alle queries with count() or sum('columnXYZ' return a "undefined index, operator" error.
Exapmle: $sale = SaleItem::whereIn('sku', $prod_array) ->whereBetween('created_at', [$start, $end]) ->count();
*

Environment

Laravel Version: 5.5.34
Laravel Model Caching Package Version: 0.2.21
PHP Version: 7.1.0

Stack Trace

*/home/vagrant/Projects/bvj-portal-55/vendor/genealabs/laravel-model-caching/src/CacheKey.php
 
                return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
            })
            ?: '';
    }
 
    protected function getQueryColumns(array $columns) : string
    {
        if ($columns === ['*'] || $columns === []) {
            return '';
        }
 
        return '_' . implode('_', $columns);
    }
 
    protected function getTypeClause($where) : string
    {
        $type =in_array($where['type'], ['In', 'Null', 'NotNull'])
            ? strtolower($where['type'])
            : strtolower($where['operator']);
 
        return str_replace(' ', '_', $type);
    }
 
    protected function getValuesClause(array $where = null) : string
    {
        return is_array(array_get($where, 'values'))
            ? '_' . implode('_', $where['values'])
            : '';
    }
 
    protected function getWhereClauses(array $wheres = []) : string
    {
        return $this->getWheres($wheres)
            ->reduce(function ($carry, $where) {
                $value = $this->getNestedClauses($where);
                $value .= $this->getColumnClauses($where);
                $value .= $this->getRawClauses($where);
                $value .= $this->getOtherClauses($where, $carry);
 
Arguments
"Undefined index: operator (View: /home/vagrant/Projects/bvj-portal-55/resources/views/start.blade.php)"*
@jetwes jetwes changed the title error oun count() or sum('column') error on count() or sum('column') Feb 12, 2018
@jetwes
Copy link
Author

jetwes commented Feb 12, 2018

updated to php 7.1.14 without any change

@mikebronner
Copy link
Owner

Hi @jetwes , thank you for reporting this. I will look into this as soon as I get back to my office on Tuesday.

@jetwes
Copy link
Author

jetwes commented Feb 12, 2018

The error seems not related to count() but to ->whereBetween
If i add 'between' to $type =in_array($where['type'], ['In', 'Null', 'NotNull','between']) ? strtolower($where['type']) : strtolower($where['operator']);
this particular error is gone

@mikebronner
Copy link
Owner

@jetwes Could you provide the stack track from laravel.log? Thanks :)

@mikebronner
Copy link
Owner

I have been able to replicate the problem and am now working on a fix 👍

@mikebronner
Copy link
Owner

Will take some time, I need to go through a few other things for this fix, won't be able to get to it today, hopefully tomorrow.

@jetwes
Copy link
Author

jetwes commented Feb 13, 2018

thank you for the update and the effort on this great package

@mikebronner
Copy link
Owner

@jetwes Please check if release 0.2.23 fixed this issue for you. Let me know how it goes. :)

@jetwes
Copy link
Author

jetwes commented Feb 14, 2018

yeah - it's looking good!

@jetwes
Copy link
Author

jetwes commented Feb 16, 2018

Sorry - too early ;) Same error when whereNotIn is used - so "NotIn" has to be added to the array, too...

@mikebronner
Copy link
Owner

@jetwes Thanks! Will fix that ASAP. :)

@mikebronner mikebronner reopened this Feb 16, 2018
@mikebronner
Copy link
Owner

@jetwes Should be fixed in 0.2.24 -- Let me know :)

@jetwes
Copy link
Author

jetwes commented Feb 18, 2018

great - thanks

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