Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other aggregations? #6

Open
lostapathy opened this issue Sep 28, 2018 · 2 comments
Open

Other aggregations? #6

lostapathy opened this issue Sep 28, 2018 · 2 comments

Comments

@lostapathy
Copy link
Contributor

Would you have any interest in a PR that adds support for other aggregations, or would you rather leave the scope of this gem as-is?

It would be really awesome to be able to have (roughly):

class Invoice < ActiveRecord::Base
  has_many :charges
  can_aggregate :charges, :total_charge_amount, "sum(quantity * amount)"
end

class Charge < ActiveRecord::Base
  belongs_to :invoice
end

Invoice.include_total_charge_amount

Or perhaps have various helpers such as this to have a nicer, if more limited, DSL.

can_sum :charges, :total_charge_amount, "quantity * amount"
@buren
Copy link
Owner

buren commented Sep 28, 2018

I like it.

I did some, very minor, research trying to find other gems that already does this (rubytoolbox, google..) and found a few things that are vaguely related, but nothing that does what you mention.

It might be something that would be useful and possible to maintain. I'll try experiment a bit first.

Thanks again @lostapathy I'll try to post back to this thread soon. (Be sure to @-mention me again here soon if I don't get back to you.)

@lostapathy
Copy link
Contributor Author

@buren I experimented with this a bit before I put this in, and definitely think it's doable. I will try to turn that into a PR for you in the next couple days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants