[erlang-questions] FW: Understanding ChicagoBoss model

Ivan Carmenates García co7eb@REDACTED
Thu May 1 21:53:30 CEST 2014


Sorry my mistake this is the correct one instead of -belongs_to(users).

 

-belongs_to_users(user1).

-belongs_to_users(user2).

 

 

 

Well I incredible make magic and guess using the so “wide” and “well
documented”  CB documentation and make up myself for the case of many to
many relationship with the same entity like user_friend_ship that have two
foreign keys of the same user entity. Using –belongs_to_users(user2).

 

-module(user_friend_ships, [

    Id,

    Users1Id,

    Users2Id

]).

 

-compile(export_all).

 

-belongs_to(users).

-belongs_to_users(user2).

 

But still have the non-useful id field thing in a many to many relation.

 

Regards,

Ivan.

 

 

 

 

Hi all,

 

I have some troubles with the CB ORM model, and I would love to know if
there is at least one way to do something like follow:

 

I have made a database model in postgres and when I tried to fix that model
in the CB model I encounter with some inconvenient, first do I have
obligatory to have and id for each table in the database? Including the many
to many normalized relationship like this one or a model with more than one
foreign keys

 

%%% Module attributes definition.

-module(user_friend_ships, [

    Id,

    Users1Id,

   Users2Id

]).

 

-compile(export_all).

 

-belongs_to(users).

 

When you compile it, it expects a field name called UsersId, even I tried to
specify in the users model de custom fk and nothing expected happens. In the
database I can have one fk called users_id that matches with one in the CB
model, but the other? It need to have a different name!.

 

-module(users, [

    Id,

    Username,

    Password,

    PasswordOld,

    Status

]).

 

-compile(export_all).

 

-has({user_friend_ships, many, [{foreign_key, "users1_id"}]}).

-has({user_friend_ships, many, [{foreign_key, "users2_id"}]}).

 

The other thing is the obligatory id even for the many to many
relationships.

 

Best regards,

Ivan.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140501/29356bfe/attachment.htm>


More information about the erlang-questions mailing list