Created
May 27, 2019 08:43
-
-
Save webzorg/fb77cb141e9ee01a017886681ed2d3dd 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
class User < ApplicationRecord | |
has_many :wallets | |
end | |
class Currency < ApplicationRecord | |
has_many :wallets | |
end | |
class Wallet < ApplicationRecord | |
belongs_to :currency | |
belongs_to :user | |
end | |
Currency.create(currency_symbol: "usd") | |
Currency.create(currency_symbol: "eur") | |
10.times do | |
user = User.create; | |
user.wallets.create(currency_symbol: "usd") | |
user.wallets.create(currency_symbol: "eur") | |
end | |
# Let's assume not all wallets were created and there's one eur wallet missing, what is the query to find it? | |
# Something like this but this is not working. | |
# | |
User.joins(wallets: :currency).where(currency_symbol: "eur", wallets: { currency: { id: nil } }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment