5

I am a newbie to erlang and chicago boss. I followed Chicago boss API documentation. I have been working with Python and Django earlier. Now in Chicago boss can we add foreign key in models.

This is my model.

model: anatomy.erl

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

There is another model.

model: species.erl

-module(species, [Id,
                 UID,
                 Name,
                 Property,
                 Anatomy,
                 Morphology   
                 Gender]).
-compile(export_all).

I have to add Anatomy as a foreign key in species table.

Laxmikant Ratnaparkhi
  • 4,745
  • 5
  • 33
  • 49

2 Answers2

3

model: anatomy.erl

-module(anatomy, [Id,
             UID,
             Name,
             Property,
             Ratio::float(),
             Value::integer(),
             Pieces::float(),
             Status]).
-has({species,many}).
-compile(export_all).

model: species.erl

-module(species, [Id,
             UID,
             Name,
             Property,
             AnatomyId,
             Morphology   
             Gender]).
-belongs_to(anatomy).
-compile(export_all).
7i11
  • 96
  • 6
1

I'm not entirely sure that I understand your question, so forgive me if this is a waste of your time. But... I think you need to rename the property in the anatomy.erl to AnatomyId and then make use of the -belongs and -has associations:

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

The -belongs_to(anatomy) will add a function, anatomy() which returns the BossRecord, of type anatomy, with the id = AnatomyId.

This will not create a relation in Mongo, but might give you the behavior you are looking for

Jr0
  • 2,131
  • 13
  • 23