Re: Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
I also solved sum field as this: Subscription.select{ (sum( Sequel[:bounty_packages][:storage_size]) + sum( Sequel[:subscription_packages][:storage_size])).as(:size) } Once again, Let me know if there is a better way. On Monday, January 14, 2019 at 8:59:09 PM UTC+3, genc wrote: > > Hi Jeremy, >

Re: Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
One thing thsat i couldn't solve is that how to fetch total sum column as :storage_size. select sum() + sum() as FIELD_NAME ... In my scenario, there are two sums and i need to name them. On Monday, January 14, 2019 at 9:36:11 PM UTC+3, genc wrote: > > As per documentation, I achieved this

Re: Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
As per documentation, I achieved this by: Subscription.select{ sum( Sequel[:bounty_packages][:storage_size]) + sum( Sequel[:subscription_packages][:storage_size]) } .left_join(:subscription_packages, id: :subscription_package_id) .left_join(:bounty_packages, id:

Second left join for sum() sees previous left join instead of main table

2019-01-14 Thread genc
Hi Jeremy, This is my SQL query: select sum(sp.storage_size) + sum(bp.storage_size) as storage_size from subscriptions s left join subscription_packages sp on s.subscription_package_id = sp.id left join bounty_packages bp on s.bounty_package_id = bp.id where s.user_id = 4; However,