Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
636 stars 200 forks source link

I got this error when use NeoEloquent in Laravel 5.4 #240

Closed yavand closed 6 years ago

yavand commented 7 years ago

Hi, Sorry for my bad English. when i use this plugin with laravel 5.3 no problem was occurd but in use with Laravel 5.4 i got this Error. whats the problem? this problem returns to Pagination and when i dont use pagination i dont have any problem.

SyntaxException: Variable article not defined (line 1, column 62 (offset: 61)) "MATCH (article:Article:Content) RETURN count(*) ORDER BY article.created_at DESC"

dimitriSpb commented 7 years ago

Hi,

I have same error and I know why (but not solution) : Prolem comes from when we use paginate + order by clause, because paginate produice 2 queries :

But in first query (count all result), there are order by to added and we need to remove it .

Example : $collection = User::orderBy('id', 'asc')->paginate(2); Error => SyntaxException: Variable user not defined (line 1, column 79 (offset: 78))\n\"MATCH (user:User) WHERE user.deleted_at is null RETURN count(*) ORDER BY id(user) ASC\"\n

Query MATCH (user:User) WHERE user.deleted_at is null RETURN count() ORDER BY id(user) ASC need to be MATCH (user:User) WHERE user.deleted_at is null RETURN count()

$collection = User::paginate(2); => OK

Anybody have a solution or can resolve this problem ?

I'm using Lumen (5.4.6) package version "vinelab/neoeloquent": "1.4.*"

PS : In documentation, for laravel 5.4 you say to use { "require": { "vinelab/neoeloquent": "dev-laravel5.4" } } But dev-laravel5.4 not exist

Thanks

dimitriSpb commented 7 years ago

Hey,

I find bug in module in this file : Vinelab\NeoEloquent\Query\Builder.php Function => getCountForPagination($columns = ['*'])

There are already comments for pagination but I think we have to uncomment functions and implements them. For moment I do it faster (not properly) and this is function :

 /**
    * Get the count of the total records for the paginator.
    *
    * @param  array  $columns
    * @return int
     */
    public function getCountForPagination($columns = ['*'])
    {
        // if I comment this paginate will work
//        $this->backupFieldsForCount();
        $orders = $this->orders;
        $this->orders = null;

        $this->aggregate = ['function' => 'count', 'columns' => $columns];

        $results = $this->get();

        $this->aggregate = null;

        // if I comment this paginate will work
//        $this->restoreFieldsForCount();
        $this->orders = $orders;

        if (isset($this->groups)) {
            return count($results);
        }

        $row = null;
        if ($results->offsetExists(0)) {
                $row = $results->offsetGet(0);
                $count = $row->offsetGet(0);
                return $count;
        } else {
                return 0;
        }
    }

Do you think you can implement it properly and merge on branch ?

Thanks

Mulkave commented 6 years ago

Is this still valid? Compatibility with 5.4 was pushed long ago. Please try again and re-open if still exists.