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

Ticket #8117 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Make calculations respect :foreign_key option for grouped associations

Reported by: kamal Assigned to: technoweenie@gmail.com
Priority: normal Milestone: 1.2.7
Component: ActiveRecord Version: edge
Severity: normal Keywords: tiny verified
Cc: kamal, tarmo

Description

Calculations currently uses the belongs_to association name when it builds the "group by <column>" SQL. This breaks the SQL if the table has a different foreign key column for that association (hence the :foreign_key option being set in the first place). This patch makes calculations use the :foreign_key value if present.

Attachments

execute_grouped_calculation_with_primary_key_name.diff (0.9 kB) - added by jack on 04/20/07 10:05:28.
Simpler patch that uses association.primary_key_name instead of ORing
calculate_grouped_association_with_foreign_key.patch (1.7 kB) - added by kamal on 06/16/07 11:38:50.
Applied jack's suggestion to the original patch with tests, tested against latest revision of activerecord r7037

Change History

04/20/07 10:05:28 changed by jack

  • attachment execute_grouped_calculation_with_primary_key_name.diff added.

Simpler patch that uses association.primary_key_name instead of ORing

04/20/07 11:29:11 changed by kamal

Much nicer!

06/01/07 01:14:36 changed by kamal

  • cc changed from kamal.fariz@gmail.com to kamal.
  • owner changed from core to bitsweat.

06/05/07 02:15:07 changed by josh

+1

06/16/07 11:38:50 changed by kamal

  • attachment calculate_grouped_association_with_foreign_key.patch added.

Applied jack's suggestion to the original patch with tests, tested against latest revision of activerecord r7037

08/25/07 06:50:57 changed by tarmo

  • cc changed from kamal to kamal, tarmo.

Applies cleanly, tests pass.

+1

09/22/07 18:29:11 changed by david

  • owner changed from bitsweat to technoweenie@gmail.com.

12/16/07 07:26:27 changed by chuyeow

  • keywords changed from tiny to tiny verified.

+1. Still applies cleanly on current trunk and tests pass.

02/02/08 04:28:46 changed by bitsweat

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

(In [8778]) Fix calculations on associations with custom :foreign_key. Closes #8117 [kamal, jack]

02/02/08 04:56:14 changed by bitsweat

(In [8779]) Merge r8778 from trunk: fix calculations on associations with custom :foreign_key. References #8117.