Fetch multiple entities core data

Discussion in 'iOS Apps' started by Jean-Bernard, Jul 27, 2013.

  1. Jean-Bernard, Jul 27, 2013
    Last edited: Jul 28, 2013

    Jean-Bernard macrumors newbie

    Joined:
    Jul 27, 2013
    #1
    I have 3 entities :Person, Address, Country. The relationship are the follow:

    Person -> Address & Address -> Person(to-one)
    Address ->Country & Country -> Address(to-one)

    In my tableView, I have all the Person present in the database and when I click on one person, I see the firstName and lastName in my UIView but I can retrieve the address of the person and of course the country also.

    How can I retrieve the good address for the person "A" and the good address for the person "B"? I have tried setRelationshipKeyPathsForPrefetching: but I don't know exactly how it works. Maybe with an ID? Or other solution....

    Can you please help me to find a solution?

    Thx
     
  2. ryanrey macrumors newbie

    Joined:
    Jul 30, 2013
    #2
    Core Data

    I am not entirely sure what you are asking, but I'll give it a shot.

    First, fetch your entities in a fetch request, specifying entityForName:mad:"nameOfEntity"

    in your entity, add an attribute for a specific id each time you create the entity. (Have a method that does this by implementing a counter)

    Before you return the fetch request make a sortDescriptor -setting the attribute as the key.
     

Share This Page