Having done a fair amount of google and looking on here I believe the following can't be done. I'm interesting in why it can't be done and people best workarounds, I offer mine below.
I use the simple department <---->> employee model, with both having a name attribute and the employee entity also having a timeWorked attribute.
The Problem
I would like to bind up a table with column one displaying departement.name and column two displaying department.@sum.employees.timeWorked. Attempting to do this results in the 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 a bind to department.employees.@count does work (but I want more!).
Other Discussions
Here's another topic here with the same problem: nstablecolumn-binding-using-collection-operators-like-sum
And another: 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 the Department Entity which performs the sum:
-(NSNumber *)departmentHours {
return [self valueForKeyPath:@"employees.@sum.timeWorked"]; }
and to then simply bind to it.
It's only a little more code at add these attributes when I want to do some sort of collation / aggregation of data but I do feel it would be more elegant to be able to bind to department.@sum.employees.timeWorked.
Any Ideas?? Reasons why it doesn't work? Better workarounds?
Cheers All