It looks like if you use will_paginate in conjunction with an
ActiveRecord named_scope with a :join, will_paginate will jam the
ids of the joined table in place of the actual ids of the returned
objects. Kinda hard to explain; it's a weird bug.
I'll pull an example from our source. Take two models, Review
and Story, where Review belongs_to :story. If I set up a simple
named scope like:
class Review < ActiveRecord::Base
named_scope :visible, :conditions => {:status => 'visible'}
end
and then do:
Review.visible.paginate(:page => 1)
All the returned reviews are OK.
However, if I just add a join to that named_scope (perfectly
legal) like:
class Review < ActiveRecord::Base
named_scope :visible, :conditions => {:status => 'visible'},
:joins => "JOIN stories ON reviews.story_id=stories.id"
end
...and then run the same paginate call as above, my results look
like:
[#<Review id: 182, story_id: 182>, #<Review id: 183, story_id: 183>, ...]
Where the story_ids are all correct and the Review ids are all
incorrectly set to match the story ids.
This has to do with how will_paginate or something is parsing
the SQL results (which are correct). Note that if I feed an
explicit :select to paginate like :select => "reviews.id,
reviews.story_id", then the ids are correct.