fixed SQL error when creating model relationships with tags