• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Managing relationships by fetching related objects within subclass of NSManagedObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Managing relationships by fetching related objects within subclass of NSManagedObject


  • Subject: Managing relationships by fetching related objects within subclass of NSManagedObject
  • From: Devarshi Kulshreshtha <email@hidden>
  • Date: Sat, 09 Feb 2013 22:50:20 +0530

Hi All,

I need some suggestions on an implementation.

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:

    @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.

Thanks,
Devarshi
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Managing relationships by fetching related objects within subclass of NSManagedObject
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Keychain issues with public key on iOS
  • Next by Date: Re: Managing relationships by fetching related objects within subclass of NSManagedObject
  • Previous by thread: Re: UI_APPEARANCE_SELECTOR question
  • Next by thread: Re: Managing relationships by fetching related objects within subclass of NSManagedObject
  • Index(es):
    • Date
    • Thread