mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.98k stars 1.19k forks source link

count is returning a hash in rails > 5 #860

Closed michelson closed 6 years ago

michelson commented 7 years ago

Hi , I'm upgrading an app to rails 5 and I've found that AATO is returning a hash on count method on ActsAsTaggableOn::Tag::ActiveRecord_Associations_CollectionProxy. This raises an error when try to get the size of the collection.

example: $irb> Profile.first.professions.size

TypeError: Hash can't be coerced into Fixnum
from /Users/michelson/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.4/lib/active_record/associations/collection_association.rb:217:in `+'

this is because the count_records method called from /active_record/associations/collection_association.rb:216 is somehow overwritten and is returning a hash {1:1}

any hints on how do you extend the count on the association collection ?

best

michelson commented 7 years ago

BTW, this started to happen from rails 5.0.0 to latest rails 5.1.4

seuros commented 6 years ago

This is fixed in 6.0.0

michelson commented 6 years ago

Hi @seuros , I'm sorry but I'm afraid that this issue is still happening:

pry(#<RSpec::ExampleGroups::Applicant::Applicant::Defaults>)> applicant.reload.user.reload.profile.professions.size
TypeError: Hash can't be coerced into Fixnum
from /Users/michelson/.rvm/gems/ruby-2.3.1/gems/activerecord-5.2.0/lib/active_record/associations/collection_association.rb:219:in `+'
[3] pry(#<RSpec::ExampleGroups::Applicant::Applicant::Defaults>)> applicant.reload.user.reload.profile.professions.count
=> {3=>1}
[4] pry(#<RSpec::ExampleGroups::Applicant::Applicant::Defaults>)> ActsAsTaggableOn
=> ActsAsTaggableOn

[5] pry(#<RSpec::ExampleGroups::Applicant::Applicant::Defaults>)> ActsAsTaggableOn::VERSION
=> "6.0.1"
subintp commented 4 years ago

Any update on this issue ? This is happening in Rails 6.0.2.1 also