Created
March 1, 2018 08:27
-
-
Save StevenJL/ffac020b6d5335a4571461d8a20bda35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Under STI, find the top 10 accounts with the greatest balances | |
# with just one query. | |
top_accounts = Account.order(balance: :desc).limit(10) | |
# Under MTI, we need to query all accounts and sort them in memory: | |
top_corporate_accts = CorporateAccount.order(balance: :desc).limit(10) | |
top_sb_accts = SmallBusinessAccount.order(balance: :desc).limit(10) | |
top_personal_accts = PersonalAccount.order(balance: :desc).limit(10) | |
top_accounts = (top_corporate_accts + top_sb_accts + top_personal_accts).sort do |acct1, acct2| | |
acct1 <=> acct2 | |
end.first(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment