使用chicagoboss将外键添加到模型中?

5 erlang chicagoboss

我是二郎和芝加哥老板的新手.我跟着芝加哥老板的API文档.我之前一直在使用Python和Django.现在在芝加哥老板我们可以在模型中添加外键.

这是我的模特.

model:anatomy.erl

-module(anatomy, [Id,
                 UID,
                 Name,
                 Property,
                 Ratio::float(),
                 Value::integer(),
                 Pieces::float(),
                 Status]).
-compile(export_all).
Run Code Online (Sandbox Code Playgroud)

还有另一种模式.

型号:species.erl

-module(species, [Id,
                 UID,
                 Name,
                 Property,
                 Anatomy,
                 Morphology   
                 Gender]).
-compile(export_all).
Run Code Online (Sandbox Code Playgroud)

我必须Anatomy在species表中添加外键.

Jr0*_*Jr0 1

我不完全确定我理解你的问题,所以如果这是浪费你的时间,请原谅我。但是...我认为您需要将 anatomy.erl 中的属性重命名为 AnatomyId,然后使用 -belongs 和 -has 关联:

module(species, [Id,
                 UID,
                 Name,
                 Property,
                 AnatomyId,
                 Morphology   
                 Gender]).
-compile(export_all).
-belongs_to(anatomy).
Run Code Online (Sandbox Code Playgroud)

-belongs_to(anatomy) 将添加一个函数 anatomy(),该函数返回 anatomy 类型的 BossRecord,其 id = AnatomyId。

这不会在 Mongo 中创建关系,但可能会为您提供您正在寻找的行为