Hi,

I have an embedded scaffold that done like this:

 <%= render  :active_scaffold => "Donations",
              :constraints => { :campaign_id => @campaign.id } %>

the amount column has a sum function attached to it. The resulting SQL
is then:

SELECT sum("donations".amount) AS sum_amount FROM "donations" LEFT
OUTER JOIN "installments" ON installments.donation_id = donations.id
LEFT OUTER JOIN "matching_grants" ON matching_grants.donation_id =
donations.id LEFT OUTER JOIN "payments" ON payments.donation_id =
donations.id LEFT OUTER JOIN "users" ON "users".id =
"donations".user_id LEFT OUTER JOIN "students" ON "students".id =
"donations".student_id WHERE ((("donations"."campaign_id" = 1)))

and the associated result is
303205.24

The same calculated in the Rails console:

>> Donation.find_all_by_campaign_id(1).sum { |p| p.amount }
=> #<BigDecimal:107deefd8,'0.29340524E6',12(24)>

So they differ - WHY ?

Turns out that the inclusion of all the JOIN tables causes the number
to go up.
Running the same SQL query without the JOIN statements causes it to be
less.

In my tables there are other columns named amount. The sum should have
been much bigger if they are in play.

Can somebody explain what is happening here - and how to we get AS to
report the right sums.

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to