This project is archived and is in readonly mode.
count with scoped :from option
-
Nobuhiro IMAI
I tryed the following:
class Foo < ActiveRecord::Base named_scope :top10, :from => "(SELECT * FROM foos ORDER BY foos.rank DESC LIMIT 10) AS foos" do def count(*args) options = args.extract_options! options[:from] ||= proxy_options[:from] args << options super(*args) end end endThis works fine with count, but doesn't make sense for (will-)paginate.
Foo.count => 20 Foo.top10.count => 10 Foo.top10.paginate(:page => 1, :per_page => 5).total_entries => 20
Is there any other solution to solve this problem?
-
CancelProfileIsBroken
- State changed from new to duplicate
