Having done quite a lot of google and looking here, I believe that the following cannot be done. I wonder why this is impossible to do, and people are best off, I suggest mine below.
I am using a simple department model <---- → employee, both of which have a name attribute and an employee object that also has a timeWorked attribute.
Problem
I would like to associate a table with a column that displays the unit of deementment.name and column two. @ sum.employees.timeWorked. Attempting to do this results in an error:
[<_NSFaultingMutableSet 0x1d5e50> addObserver:forKeyPath:options:context:] is not supported. Key path: timeWorked Cannot remove an observer <NSTableBinder 0x1a9280> for the key path "employees.timeWorked" from <Depatement 0x1faf40> because it is not registered as an observer.
However, binding to department.employees. @count works (but I want more!).
Other discussions
Here's another topic here with the same problem: nstablecolumn-binding-using-collection-operators-like-sum
And more: cocoa-bindings-binding-to-the-many-end-of-a-to-many-relationship
My workaround
My solution to this problem is to create an attribute for a department object that does the sum:
-(NSNumber *)departmentHours { return [self valueForKeyPath:@" employees.@sum.timeWorked "]; }
and then just get attached to it.
This is just a little more code to add these attributes when I want to do some sorting / aggregation of data, but I feel it would be more elegant to be able to bind to a department. @ sum.employees.timeWorked.
Any ideas? Reasons why this does not work? Better workarounds?
Greetings to all
source share