Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
Say I have an employee entity and a company entity in core data.

So employee and company are related to each other like this:

Employee <<---> Company

Now I am trying to right a manageRelationships method in each class, something like this:

Code:
    @interface Employee : NSManagedObject
    - (void)manageRelationships;
    @property (nonatomic, retain) Company *company; // for relationship
    @property (nonatomic, retain) NSNumber *companyId; // acts as foreign key 
    @end
    
    @implementation Employee
    @dynamic company;
    @dynamic companyId;
    - (void)manageRelationships
    {
       // prepare a predicate as @"companyId == %@",self.companyId
    
       // execute a fetch request against Company entity
    
       // map relationship using self.company = retrievedCompanyObject
    }
Now I have few questions:

1. Is it safe to fire fetch request and map a relationship, as implemented above, within a subclass of NSManagedObject?

2. Is their any better way to achieve it? (Idea behind above approach is- I will be calling above method on each created managed object so that it automatically manages and maps all associated relationships)

Please suggest.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.