cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
537 stars 72 forks source link

Scopes return SQLSTATE[42000]: Syntax error or access violation #74

Closed csb346 closed 5 years ago

csb346 commented 6 years ago

Hi! I need some help.

I already used this package on other projects without any problem. This time I don't understand why, but scopes are returning an sql syntax error. A simple example test:

$article->tag('banana');
$tagged = Article::withAllTags('banana')->get();

SQLSTATE[42000]: Syntax error or access violation: 1055 'wr.articles.title' isn't in GROUP BY (SQL: select `articles`.* from `articles` inner join `taggable_taggables` on `articles`.`id` = `taggable_taggables`.`taggable_id` and `taggable_taggables`.`taggable_type` = App\Article where `taggable_taggables`.`tag_id` in (695) group by `articles`.`id` having COUNT(taggable_taggables.tag_id) = 1)

Any idea why? I can't find any error. Anyway this query is from the package and never had any problem before.

Thanks.

cviebrock commented 6 years ago

I'm going to guess it's related to https://github.com/cviebrock/eloquent-taggable/issues/60#issuecomment-330493812 ... which really doesn't have a fix, since I can't know what all the columns are in your articles table.

Unless you can turn off strict mode, I don't have an easy solution.

wemteqdev commented 6 years ago

I got this error too

chris9owen commented 5 years ago

Well you don't need to know what is in the articles table. The function is just returning a list of article ids which you are using explicitly in the group by. group by articles.id. No need to use * in this case.

cviebrock commented 5 years ago

I'm definitely open to a PR that can fix this.

cviebrock commented 5 years ago

Closing due to no response. Feel free to re-open or comment if you are still having issues.

MordiSacks commented 4 years ago

This is my solution

$tags = ['tag1', 'tag2', 'tag3'];

$taggable = Taggable::query();

foreach ($tags as $tag) {
    $taggable->whereHas('tags', function (Builder $q) use ($tag) {
        $q->where('normalized', $tag);
    });
}

got it from here https://github.com/spatie/laravel-tags/blob/master/src/HasTags.php#L79

andiLeong commented 4 years ago

hey thanks for the efforts was put to build up this package, unfortuantely I am also encountering this issue.thanks