views:

45

answers:

2

I have a datamodel with to-many to-many relations. Using the example of employee database let say the entity division is related to department which in turn is related to employee. The employee has an attribute salary. How best to have a attribute at the level of division which is derived from the salary attribute. For example average salary or maximum salary.

I would need those attributes to sort the list of departments.

A: 

Have a look at the KVC Set and Array Operators. Using one of these (@avg in your example) wrapped in a custom read only property should fit the bill.

JeremyP
+1  A: 

Have a look at this question in the Core Data FAQ. If you can't do it with KVC set/array operators, then you try to do the keyPathsForValuesAffectingValueForKey : trick. If that isn't viable, you have to use KVO to observe changes in the key path the value is derived from.

Tom Dalling