<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=ES-MX link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span lang=EN-US>Hi all,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>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).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-module(user_friend_ships, [<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Id,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Users1Id,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Users2Id<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US>]).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-compile(export_all).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-belongs_to(users).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>-belongs_to_users(user2).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>But still have the non-useful id field thing in a many to many relation.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Ivan.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><div style='mso-element:para-border-div;border:none;border-bottom:solid windowtext 1.0pt;padding:0cm 0cm 1.0pt 0cm'><p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US><o:p> </o:p></span></p></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>Hi all,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>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:<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>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<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>%%% Module attributes definition.<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US>-module(user_friend_ships, [<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> </span>Id,<o:p></o:p></p><p class=MsoPlainText><span lang=EN-US> Users1Id,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Users2Id<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US>]).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-compile(export_all).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-belongs_to(users).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>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!.<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-module(users, [<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Id,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Username,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Password,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> PasswordOld,<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US> Status<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US>]).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-compile(export_all).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>-has({user_friend_ships, many, [{foreign_key, "users1_id"}]}).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US>-has({user_friend_ships, many, [{foreign_key, "users2_id"}]}).<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText><span lang=EN-US>The other thing is the obligatory id even for the many to many relationships.<o:p></o:p></span></p><p class=MsoPlainText><span lang=EN-US><o:p> </o:p></span></p><p class=MsoPlainText>Best regards,<o:p></o:p></p><p class=MsoPlainText>Ivan.<o:p></o:p></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></body></html>