Fixed SQL generation causing UndefineTable error

This fixes issue #73.

Taken from commit eb4ef67d4b28655e120c399f971a0cf71b88fa97 from redminecrm/redmine_tags