Ahoy!
I’ve got two patches in Trac that fix cases where the finder for a has_many association works with :include but it’s count() fails.
http://dev.rubyonrails.org/ticket/9167 http://dev.rubyonrails.org/ticket/9175
Both are small, well-tested and fix existing features without adding new ones.
Could some folks take a look at them?
Descriptions included below in case you’d prefer to read about them here.
Thanks, ::Jack Danger
When defining an association like the following: Author < ActiveRecord::Base has_many :posts_with_no_comments, :class_name => ‘Post’, :conditions => ‘comments.id is null’, :include => :comments end
The find() works. What doesn’t work is asking for the size of the association before it’s been cached. @author.posts_with_no_comments.size # => ERROR
@author.posts_with_no_comments # => [#<Post … >, #<Post … >]
It’s a tiny patch - the association just needs to pass along the :include option to the count method. http://dev.rubyonrails.org/ticket/9175
For this simple has_many association: class Author; has_many :posts; end This works: @author.posts.find(:all, :include => :comments, :conditions => ’ comments.id is null’) This fails: @author.posts.count(:all, :include => :comments, :conditions => ‘comments.id is null’)
The fix is to not clobber the :include option that gets passed explicitly. It’s a two-character patch.