What is the best way to create derived properties

I have a datamodel with a to-many to-many relationship. Using an example employee database, suppose that a department unit is associated with a department, which, in turn, is associated with an employee. The employee has an attribute salary. What is the best way to have an attribute at the division level, which is obtained from the salary attribute. For example, the average salary or maximum salary.

I need these attributes to sort the list of departments.

+3
source share
2 answers

See this question in the master data FAQ. If you cannot do this with the KVC set / array statements , try the trick keyPathsForValuesAffectingValueForKey :. If this is not practical, you should use KVO to observe the changes in the key path to which the value is received.

+2
source

Check out the KVC Set and Array Operators . Using one of them (@avg in your example) enclosed in a read-only user property should match the bill.

+1
source

Source: https://habr.com/ru/post/1745734/


All Articles