How to model a gambling system? Or how to avoid ternary relationship?

Hello, and thank you for your impressive work. I searched for graph DBs a few months ago and missed (!!) dGraph, now I found it I’m really excited to begin working with it.

In my current project I’d like to model something that seems to require ternary relationships, but maybe there is another way to do it.

My data structure is similar to the following gambling system:

  • sport teams play games
  • gamblers bet on who wins and with what score

Team A et team B will play together.
Gamblers G1 and G2 make their bet:

  • G1 bets A will beat B with a score of 3
  • G2 bets B will bet A with a score of 1

My hypothetical graph would have nodes for gamblers and teams, and edges like:

  • “beats with score N”
  • “bet on a team couple, a winner and a score” -> an edge pointing to an edge?

As dGraph doesn’t have ternary relationships, my only idea is to duplicate team nodes: Each time a gambler makes a bet on 2 teams, I duplicate the 2 teams nodes and link the duplicates to the player. Then I can easily link those duplicates with the player’s bet.

Any idea to do it with less redundancy?

Thank you!

Hi @myo

The exact modelling of your data would primarily depend on what kind of queries do you want to perform.

Regarding duplicates, I think there is some confusion. In Dgraph, you don’t have to create any duplicates. You just have to create an edge to an already existing node.

I’ll try and explain using an example. This might not be the exact structure that you want to use.

_:team1 <name> "Arsenal" .
_:team2 <name> "Manchester United" .

_:gambler1 <bet> _:b1 .
_:b1 <team> _:team1 .
_:b1 <team> _:team2 .
_:b1 <winner> _:team1 .
_:b1 <difference> "3" .

Here, when we add the teams for the bet, b1 we aren’t creating any copies. We just link the teams so that we could traverse them. Is this what you meant?

1 Like

Thank you @pawan, I didn’t thought bets as nodes, it seems to fit well with my queries.
Keep up the good work!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.