How to represent a 2-to-many relationship in ErlyDB ?

1 view
Skip to first unread message

unita_logica

unread,
May 10, 2009, 11:18:41 PM5/10/09
to erlyweb
I have a very simple DB representing a chess game/player scenario:

Player table: {id, name, score, etc}
Game table: {id, white_id, black_id}

As you can see a Game is strictly a 2-to-many relationship so the
easiest way to handle this is having 2 foreign keys (white and black
players) exist in the Game table. I am aware my foreign key should be
named "player_id" but in this case it obviously can't work as I would
have 2 foreign keys with the same name.

How do I tell ErlyDB to use my foreign keys in the Game table? Or how
should I name them?

Thanks in advance.

Alexander Dergachev

unread,
May 11, 2009, 2:11:54 AM5/11/09
to erl...@googlegroups.com
Hi!

I`m sorry, but don`t you think that 2-to-many it`s the same as many-to-many? :)

So, did you have a look at this page?
http://yarivsblog.com/articles/2006/08/30/many-to-many-relations-are-now-at-an-erlydb-near-you/

Just have a look, and I guess you won`t have this kind of question :)

Good luck!
--
With Best Regards,
Alexander Dergachev

unita_logica

unread,
May 11, 2009, 2:51:29 AM5/11/09
to erlyweb
Yes, I did read about many-to-many relationships before posting. And
you're right, 2 qualifies as "many".

However, like I described, this is a special case of many-to-many. As
far as DB design goes, there is no need for a relation table between
games and players because there are 2 and only 2 players per game.
It's natural to keep 2 foreign keys in the games table instead. I can
of course add a relation table, but it would be a complication needed
only to satisfy a (supposed?) ErlyDB requirement.

I read the official docs and they seem to imply this is not supported,
so (since I am new to ErlyDB) I was asking if I can keep my current DB
structure (which is the most natural) and still capture its relations
in ErlyDB.

Thanks again.


On May 10, 11:11 pm, Alexander Dergachev <cy6erbr...@gmail.com> wrote:
> Hi!
>
> I`m sorry, but don`t you think that 2-to-many it`s the same as many-to-many?
> :)
>
> So, did you have a look at this page?http://yarivsblog.com/articles/2006/08/30/many-to-many-relations-are-...
Reply all
Reply to author
Forward
0 new messages