Reputation: 89
I'm trying to get all transactions
in a postgresql db
, transactions
have a one-to-one relationship with the pairs
table. In the pairs table, there's a column called match
with type json. I want to select all transactions
including their pair
whose pair.match
count is greater than 1.
I tried pairs = Pair.where('json_array_length(match) > 1')
which worked.
How do I get all transactions where pair.match
is greater than 1. Tried this -> transactions = Transactions.includes(:pair).where(pairs: 'json_array_length(match) > 1')
but didn't work.
Update: It's Transaction
not Transactions
Upvotes: 0
Views: 606
Reputation: 3041
A couple of observations:
I know I'm not answering the question, but this is too much for a comment and you need to fix these issues before going on.
Upvotes: 2
Reputation: 2428
You can try joining the two tables. Supposing that your models are Pair and Transaction
transactions = Transaction.joins(:pair).where('json_array_length(match) > 1')
Upvotes: 1