Rollup on an associatated model column
Closed this issue · 3 comments
cimm commented
Is it possible to use a column from an associated model as the rollup column?
Take a User
model belonging to an Account
model and I want to count the users by account creation time as an example. I tried the following two but Rollup does not seem to understand.
User.includes(:account).rollup(:users_per_month, column: 'accounts.created_at', interval: :month)
User.includes(:account).rollup(:users_per_month, column: {account: :created_at}, interval: :month)
Thank you!
ankane commented
Hey @cimm, it should work with joins
instead of includes
:
User.joins(:account).rollup(:users_per_month, column: 'accounts.created_at', interval: :month)
cimm commented
Indeed, that does work! I tried with joins
but had another typo I missed. Sorry!
Thank you for the great gem (and your "Securing Sensitive Data in Rails" article, which I really enjoyed).