How to manage one-to-many relationship in Core Data?
I am having a hard time figuring out some things about how Core Data handles its database. I will explain my problems with a concrete example:

Let's just say that we have the following schema where there are departments which hold numerous accounts (our addresses).

I have created my Core Data file using the editor. In the CachedDepartment class, I have added the necessary attributes, and I have created a to-many relationship, and I have selected "Inverse" to the "Department property of my CachedAccount. CacheAccount also has attributes, and a relationship inverse to the "addresses" relationship of CachedDepartment.

I have the following sources (I give you the 2 header files. The rest contain nothing of interest):

    @interface CachedAccount : NSManagedObject {
    @private
    }
    @property (nonatomic, retain) NSNumber * accountID;
    @property (nonatomic, retain) NSString * email;
    @property (nonatomic, retain) NSString * name;
    @property (nonatomic, retain) CachedDepartment *department;
    @end
    
    @class CachedAccount;
    
    @interface CachedDepartment : NSManagedObject {
    @private
    }
    @property (nonatomic, retain) NSString * departmentID;
    @property (nonatomic, retain) NSString * departmentName;
    @property (nonatomic, retain) NSSet *addresses;
    @end
    
    @interface CachedDepartment (CoreDataGeneratedAccessors)
    
    - (void)addAddressesObject:(CachedAccount *)value;
    - (void)removeAddressesObject:(CachedAccount *)value;
    - (void)addAddresses:(NSSet *)values;
    - (void)removeAddresses:(NSSet *)values;
    
    @end

And now the questions:
<br>
-- How should an account and department objects be created so that a one-to-many relationship will be established?<br><br>
-- What should I do with CoreDataGeneratedAccessors?After creation, should I call the -addAddressesObject function of CachedDepartment or I will need to make something like anAccount.department = aDepartment and that's it?<br><br>
-- In each case when creating objects how can I make sure that adding an address to a department won't create a double instance of the address and store it?<br><br>

I would appreciate any insights on this.
How to manage one-to-many relationship in Core Data?
===

I am having a hard time figuring out some things about how Core Data handles its database. I will explain my problems with a concrete example:

Let's just say that we have the following schema where there are departments which hold numerous accounts (our addresses).

I have created my Core Data file using the editor. In the CachedDepartment class, I have added the necessary attributes, and I have created a to-many relationship, and I have selected "Inverse" to the "Department property of my CachedAccount. CacheAccount also has attributes, and a relationship inverse to the "addresses" relationship of CachedDepartment.

I have the following sources (I give you the 2 header files. The rest contain nothing of interest):

    @interface CachedAccount : NSManagedObject {
    @private
    }
    @property (nonatomic, retain) NSNumber * accountID;
    @property (nonatomic, retain) NSString * email;
    @property (nonatomic, retain) NSString * name;
    @property (nonatomic, retain) CachedDepartment *department;
    @end
    
    @class CachedAccount;
    
    @interface CachedDepartment : NSManagedObject {
    @private
    }
    @property (nonatomic, retain) NSString * departmentID;
    @property (nonatomic, retain) NSString * departmentName;
    @property (nonatomic, retain) NSSet *addresses;
    @end
    
    @interface CachedDepartment (CoreDataGeneratedAccessors)
    
    - (void)addAddressesObject:(CachedAccount *)value;
    - (void)removeAddressesObject:(CachedAccount *)value;
    - (void)addAddresses:(NSSet *)values;
    - (void)removeAddresses:(NSSet *)values;
    
    @end

And now the questions:
<br>
-- How should an account and department objects be created so that a one-to-many relationship will be established?<br><br>
-- What should I do with CoreDataGeneratedAccessors?After creation, should I call the -addAddressesObject function of CachedDepartment or I will need to make something like anAccount.department = aDepartment and that's it?<br><br>
-- In each case when creating objects how can I make sure that adding an address to a department won't create a double instance of the address and store it?<br><br>

I would appreciate any insights on this.