cviebrock / eloquent-taggable

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

getAllTags on Postgres #23

Closed dj0nes closed 8 years ago

dj0nes commented 8 years ago

Postgres doesn't like the orderBy statement in the util.php function getAllTags, and returns the following query error:

SQLSTATE[42P10]: Invalid column reference: 7 ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...ags"."tag_id" where "taggable_type" = $1 order by "taggable_...
^ (SQL: select distinct "normalized" from "taggable_taggables" inner join "taggable_tags" on "taggable_taggables"."taggable_id" = "taggable_tags"."tag_id" where "taggable_type" = App\Blog order by "taggable_tags"."normalized" asc)

where App\Blog just happens to be my model.

My quick fix for this is just commenting out line 91 in util.php to skip the orderBy statement, and doing the sorting elsewhere.

eloquent-taggable/src/Util.php

    public static function getAllTags($className)
    {
        return DB::table('taggable_taggables')->distinct()
            ->where('taggable_type', '=', $className)
            ->join('taggable_tags', 'taggable_taggables.taggable_id', '=', 'taggable_tags.tag_id')
            // ->orderBy('taggable_tags.normalized')
            ->lists('taggable_tags.normalized');
    }
cviebrock commented 8 years ago

Closing ... try the 2.0 branch which fixes lots of Laravel 5.1+ issues. I don't have a Postgres instance to test against, but I did remove the "ORDER BY" part from the new function that does the above, so I imagine it will work.

Can you re-open if it's broken again? Thanks!