Discussion Forum

Modeling one to many relationships


We are evaluating grakn for a commercial project - it looks like a great product, especially the visualizer and the query language ! We hit some issues while trying to model our schema, though - I would like to model a company (entity) which has a list of projects and a list of employees. My assumption was that this could be modeled as an attribute, but it looks like this isn’t possible with GRAKN, so I would need to use relationships, similar to how it is described in this thread:

Is there any particular reason lists aren’t supported with grakn? I mean, a company can have a name (attr string) but can’t have a list of employee names (list of string)

Thank you,

Hi @attodorov,

Entities in Grakn are “hyper-entities”. You are actually able to assign multiple instances of an attribute in a given entity.

For example, a person with 3 emails will simply look like this:

person sub entity,
has email;
insert $x isa person, 
has email "first@email.com", 
has email "second@email.com",
has email "third@email.com";

we are also adding cardinality restrictions, which will be available soon.

So, in summary, it is possible to do what you asked for. However, I may not recommend it as the best approach.

Objects in your domain should be represented as entities, which is comprised of a set attributes, relationships should relate objects in contextual way, and attributes should behave as stand-alone values which carry no meaning other than it’s value (e.g. the age:18 has no meaning when it’s alone).

Thus, I would recommend you model the employees are person sub entity. For example:


company sub entity,
has name,
plays employer;

person sub entity,
has name,
plays employee;

employment sub relationship,
relates employee,
relates employer;

Let me know if that helps…

1 Like

makes perfect sense, thanks. I suppose that using the suggested approach, I can also get more insightful and meaningful results from my knowledge base graph queries.