I try to do a scope to easy get the users not already played games, the table structures looks like:
users
- id
- username
games
- id
user_games
- id
- user_id
- game_id
Here is a sqlfiddle: http://sqlfiddle.com/#!9/fe9d19/3
If the user already have played game with ID 2, it should no longer count with it in games_left
. So to just to be clear, the result I try to get is something like:
{
"id" => 1,
"username" => "test",
"games_left" => 2
}
any help is much appreciated, thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire