[baseten-users] More relationships coding

Tuukka Norri tuukka.norri at karppinen.fi
Mon May 4 18:23:56 EEST 2009


Hi!

Réjean Lamy kirjoitti 2.5.2009 kello 0.50:
> In the original example, CoreData generated the accessors so we can  
> tap in the add/remove objects methods when an Department's employee  
> is added/removed.
>
> @interface Department (CoreDataGeneratedAccessors)
> - (void)addEmployeesObject:(Employee *)value;
> - (void)removeEmployeesObject:(Employee *)value;
> @end
>
> I would like to know how using the BX APi I can emulate this  
> CoreData mechanism.
>
> In the Hillegass Depts example, this is needed to monitor when a  
> department's manager is removed from the department so the manager  
> popup value can be adjusted according. Here we only need the remove  
> method, but with CoreData they come in pairs (ref: Hillegass page  
> 368).

This is possible using the collections returned by BXDatabaseObject.  
If you have method calls like these, the KVO methods should get called  
automatically:

[[department primitiveValueForKey: @"Employee"] addObject: employee];
[[department primitiveValueForKey: @"Employee"] removeObject: employee];

In case you use SVN trunk, you can use keys like these:

[[department primitiveValueForKey: @"EmployeeSet"] addObject: employee];
[[department primitiveValueForKey: @"EmployeeSet"] removeObject:  
employee];
-- 
Best regards,
Tuukka Norri
MK&C



More information about the baseten-users mailing list