ActiveRecord::Associations::AssociationCollection#any? broken since rails-rev9199
-
Aaron H.
I believe I have a fix for this.
Investigating has found that the issue lies in how will_paginate mixes in the paginate method_missing magic.
In line 44 of finder.rb, will_paginate collects the classes of all AssociationCollection classes, then pushes associations::HasManyThrough into the array and adds the paginate missing method to all subclasses. However, since 9200, HasManyThrough is now descendent from AssociationCollection, this is unnecessary and seems to cause a redundancy by adding a missing method the 2nd time.
In order to make will_paginate work properly with projects running Rails versions before or after 9200, adding a call to .uniq before .each on line 44 seems to fix the problem.
(collection.instance_methods.include?(:create!) ?
collection : collection.subclasses.map(&:constantize)
- ).push(associations::HasManyThroughAssociation).each do |klass| + ).push(associations::HasManyThroughAssociation).uniq.each do |klass|
klass.class_eval do
include Finder::ClassMethods
I’ve just worked on this and testing is minimal, but it seems to be a 100% fix.
-
Geoff Garside
Thanks Aaron, my initial fix was a bit more simplistic (delete the .push) but yours is much cleaner. Its always a terrible feeling of dread when you update vendor/ run your tests and loads of things go wrong.
-
Martin Gamsjaeger (snusnu)
Hey guys,
I can confirm that this fixed all my errors, although I found the offending line 44 in will_paginate.rb and not finder.rb ;-)
Thx so much! You rock hard! 4hours! Awesome ;)!
cheers
Martin Gamsjaeger
-
Mislav
- Assigned user changed from Chris Wanstrath to Mislav
OK, I lied. But now it's resolved properly http://github.com/mislav/will_pa...
-
wildchild
Broken again (SystemStackError: stack level too deep) after AR associations refactoring (r9233) :(
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.