0

I have been breaking my head trying to do something simple but i can't. Im using rails version 4.2.6

The thing is that i have this three models with the next values.

Bet
   match_id
   #more values..

Match
   #values...

MatchResult
   match_id (One to one relation with match, that means i have a has_one...)
   #more values...

what im trying to do is something like this

Bet.where(:match => {:match_results => nil})

Also tried using Bet.joins() method but its not working, i saw and tried also something like this post, but i could not figure out a way. Rails Nested Joins Activerecord with conditions

So basically i want to bring all Bets which have a Match which does not have any Match_result.match_id. If i get Match.first.match_result it does work and bring me one. Is there any way to bring them?

Thanks!

strivedi183
  • 4,749
  • 2
  • 31
  • 38
Agustin
  • 95
  • 2
  • 10
  • Did you try to join like this? https://stackoverflow.com/questions/43588263/activemodel-search-by-association/43588738#43588738 – Bittu Choudhary May 23 '17 at 06:15

1 Answers1

3
Bet.includes(match: :match_result).where(match_results: { id: nil })
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145