Model property
Similar to the concepts of calculated property of programming languages, model properties in Teo represents data inputs and outputs which have a calculated nature. It's saved into the database if it's cached.
Property getter
A readable property has a getter. The getter is a pipeline that returns a value of declared data type. Field dependencies should be declared, too if it's cached.
In this example, name
is calculated with firstName
and lastName
. Since
it depends on firstName
and lastName
, the deps
list is also
declared.
Property setter
A writable property has a setter. The value is finally set to other fields of the object.
Let's add a setter to the readonly property in the previous section.
Now, this property is readwrite. You can read from it and write to it.
Cached property
If the calculation is heavy loading, why not just save the value in memory and database? Cached property cames to the rescue.
When a property is cached, there is a table column for it. Unless any value of its dependency fields are updated, this value won't be recalculated.
Index
Like model scalar fields, calculated properties can be indexed. The API works the same way.