Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10254 (reopened enhancement)

Opened 1 year ago

Last modified 10 months ago

[PATCH][TINY] count(...) in calculations.rb does not support :from option

Reported by: bloopletech Assigned to: core
Priority: normal Milestone: 1.2.7
Component: ActiveRecord Version: edge
Severity: normal Keywords: tiny patch
Cc: obrie

Description

The count method in calculations.rb can be called with a similar argument structure to ActiveRecord::Base#find. The will_paginate plugin calls count internally whenever a paginate call is made, to count how many results to return. Unfortunately, count() does not support the :from option, whereas find does. This causes problems in that if you try to call paginate(... :from => "table" ...), you will get an error from calculations.rb This patch adds :from support to calculations.rb. It's my first patch, so please be gentle :-)

Attachments

activerecord_calculations_fix.diff (2.3 kB) - added by bloopletech on 11/23/07 03:17:56.
Updated patch
activerecord_calculations_from_test.diff (0.6 kB) - added by michaelboutros on 01/01/08 08:28:23.
activerecord_calculations_from_(fix).diff (2.5 kB) - added by michaelboutros on 01/01/08 19:26:34.

Change History

11/23/07 03:17:56 changed by bloopletech

  • attachment activerecord_calculations_fix.diff added.

Updated patch

11/23/07 03:18:55 changed by bloopletech

  • keywords set to tiny patch.

Updated the patch to update the documentation to include "from". Documentation for from attribute copied from find() documentation.

12/17/07 00:20:33 changed by david

  • status changed from new to closed.
  • resolution set to incomplete.

Currently fails against trunk and should really have a test as well. Thanks for working on this! Reopen when fixed.

01/01/08 08:28:23 changed by michaelboutros

  • attachment activerecord_calculations_from_test.diff added.

01/01/08 08:28:40 changed by michaelboutros

  • status changed from closed to reopened.
  • resolution deleted.

activerecord_calculations_from_(fix)

01/01/08 08:31:44 changed by michaelboutros

I adjusted the original patch so that it'd work in Rails 2.0; no code changes, just some line numbers have changed. I also added a test that borrowed code from an earlier test, but added the 'from' option - simple, but it shows that the patch and feature work as intended.

First submission from me, so, like the original poster asked, please go easy on me :)

PS: I apologize about the earlier post, any way to delete it?

01/01/08 08:43:00 changed by ssoroka

documentation is duplicated on lines 29-30 and 31-32

01/01/08 19:26:34 changed by michaelboutros

  • attachment activerecord_calculations_from_(fix).diff added.

01/01/08 19:27:18 changed by michaelboutros

You're right, fixed it.

01/25/08 18:21:50 changed by obrie

  • cc set to obrie.

01/25/08 18:30:36 changed by obrie

I would actually propose that this checks scope[:from] as well. You'll notice that the finder sql will check scope[:from], options[:from], and table_name (in that order).