Basics of associations / relations in BossDB

73 views Asked by At

Playing around with Chicago Boss, I have a model like this:

-module(person, [Id, Name]).
-compile(export_all).

Lets say that I want to add the persons friends and foes. I came up with this.

-module(person, [Id, Name]).
-compile(export_all).
-has({dependency, many, [{foreign_key, "person1_id"}]}).
-has({dependency, many, [{foreign_key, "person2_id"}]}).

-module(friend, [Id, Person1, Person2]).
-compile(export_all).
-belongs_to_person(person1).
-belongs_to_person(person2).

-module(friend, [Id, Person1, Person2]).
-compile(export_all).
-belongs_to_person(person1).
-belongs_to_person(person2).

This seems to do what I want, even though the key names probably needs to change to something more intuitive.

However, I'm just beginning to learn Erlang and wonder if this is the best way to do it. I'm using mnesia as backend for BossDB and I get the impression that mnesia could handle this in a nicer way. Am I better of without CB models and use mnesia (or dets) from the controllers?

0

There are 0 answers