acts-as-taggable-on icon indicating copy to clipboard operation
acts-as-taggable-on copied to clipboard

.tagged_with([], any:true) always selects all fields, v.6.0.0

Open sgalichkin opened this issue 6 years ago • 1 comments

Hi all,

the query below selects only ids as expected and can be used later e.g. in where statement:

Person.tagged_with(['tag1', 'tag2']).select(:id)

but the next query selects all fields, ignoring select(:id):

Person.tagged_with(['tag1', 'tag2'], any: true).select(:id)

I found the following code in any_tags_query.rb:

def build
  taggable_model.select(all_fields)
                .where(model_has_at_least_one_tag)
                .order(Arel.sql(order_conditions))
                .readonly(false)
end

Can the select(all_fileds) statement be removed?

Meanwhile, the workaround I've found is to unscope select fromtagged_with first and then select necessary fields:

Person.tagged_with(['tag1', 'tag2']).unscope(:select).select(:id)

sgalichkin avatar Jan 14 '19 10:01 sgalichkin

Same issue here, thanks for your workaround!

hackhowtofaq avatar May 22 '20 08:05 hackhowtofaq