Calling find on a HABTM-scoped collection returns incorrect results under some circumstances if there are duplicate links in the database. I've set :uniq => true on the relationship between Post and Category and written some test cases to demonstrate. In the patch, the second and fifth tests are the ones that fail, i.e.
# Returns duplicate results
category.posts.find(:all)
# Returns too few results as uniqueness is imposed in Ruby after the results
# come back from the DB, rather than being enforced by the DB query
category.posts.find(:all, :limit => 2, :include => :author_with_posts)
I've been trying to work around this in my project and I'm going round in circles trying to get both eager loading and result set size to work correctly. I'm not sure that the first example is really a bug, as the find is pretty much redundant and could be useful if you actually want to pull out duplicates from the DB. The second example is infuriating though.