Short database schema:
- users (id)
- games (current_player_id) // has many cards
- cards (author_id, game_id, content, created_at)
- game_views(game_id, user_id) //shows which games user have seen
I need to find game for user, which meets all whose rules:
- game's current_player is NULL (the game do not played by anybody right now)
- author of the last card in game(order by created_at, I think) is not user
- game have not been seen by user
I use PostgreSQL.