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

SQL Error in Pgsql DB #225

Closed
efriandika opened this issue Apr 14, 2017 · 3 comments
Closed

SQL Error in Pgsql DB #225

efriandika opened this issue Apr 14, 2017 · 3 comments
Assignees
Labels
bug Issue, error or unexpected behavior

Comments

@efriandika
Copy link

efriandika commented Apr 14, 2017

I got SQL Error like this:

SQLSTATE[42803]: Grouping error: 7 ERROR: column "audits.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ... null and "audits"."auditable_type" = $2 order by "created_a...
^ (SQL: select count(*) as aggregate from "audits" where "audits"."auditable_id" = 2 and "audits"."auditable_id" is not null and "audits"."auditable_type" = App\Models\User order by "created_at" desc)

Is it a bugs ?

@efriandika
Copy link
Author

I think this is a bugs in the:
src/Driver/Database.php

...
$total = $model->audits()->count();
...

src/Auditable.php

...
public function audits()
    {
        return $this->morphMany(AuditModel::class, 'auditable')
            ->orderBy('created_at', 'DESC');
    }
...

Both of them make an SQL Error in Pgsql:

SQLSTATE[42803]: Grouping error: 7 ERROR: column "audits.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ... null and "audits"."auditable_type" = $2 order by "created_a...

@efriandika efriandika changed the title SQL Error SQL Error in Pgsql DB Apr 14, 2017
@quetzyg quetzyg self-assigned this Apr 23, 2017
@quetzyg quetzyg added the bug Issue, error or unexpected behavior label Apr 30, 2017
@quetzyg
Copy link
Contributor

quetzyg commented Apr 30, 2017

Today I had some time to look into this and I managed to replicate the issue. Like you pointed out, it's due to the orderBy('created_at', 'DESC') in the audits() relation method in the Auditable trait.

I found a similar issue, which lead me to the solution.

@efriandika
Copy link
Author

Thank you very much @quetzyg 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue, error or unexpected behavior
Projects
None yet
Development

No branches or pull requests

2 participants