T
TypeDB•2mo ago
kenho811

< Attribute Value defined as function output?>

< Generated Attribute ??>
4 Replies
kenho811
kenho811OP•2mo ago
I am looking at the University and Student example here. https://development--typedb-docs.netlify.app/new_home/get_started/schema#_defining_your_schema
define
entity company sub organization;
entity university sub organization;


define
attribute student-count, value integer;
relation enrolment, relates university, relates student;
university owns student-count, plays enrolment:university;
user plays enrolment:student;
define
entity company sub organization;
entity university sub organization;


define
attribute student-count, value integer;
relation enrolment, relates university, relates student;
university owns student-count, plays enrolment:university;
user plays enrolment:student;
In this example, the university entity and student entity are related via the enrollment relation. In addition, university entity has an attribute called student-count. Given that student count is basically the number of enrollment relation where university = SomeUniversity, it feels like the student-count attribute is derivable from just counting number of enrollment relation where university=SomeUniversity. ------ Is there something like
Define entity university, owns student-count as get_student_count(university)
Define entity university, owns student-count as get_student_count(university)
where get_student_count is a function which takes unviersity by name, and output a number, based on the relation? Benefit is that, if the attribute value can be derived from a function, then - when there's a new enrollment, we dont need to update both student-count + add a new enrollment relation data.
krishnan
krishnan•2mo ago
This is basically the 2.x rule system we moved away from. In 3.x you're expected to use the function directly and not have the attribute.
kenho811
kenho811OP•2mo ago
Understood. For clarity, would it be possible to see the function's signature on the web console's UI? I suppose it would be nice to be reminded of the custom functions when browsing the web console.
Joshua
Joshua•2mo ago
yeah it's a good point, we should have it in studio let's continue in the other thread although, i do think there's an interesting future something like what you've written with function-computed attribute values, but it's not on the roadmap/prioritized in the near future @kenho811 🙂

Did you find this page helpful?