views:

113

answers:

1

Hi,

I have situation where I dont want to add records to the relation table. For example :

I have "TRIPS" entity and it has attribute for "LOCATION_ID", I am filling it when user creates a new TRIP and select a LOCATION from the LOCATIONS entity

In "LOCATIONS" entity I am allowing user to create locations and I am assigning a unique ID to each location.data will not be repeated here.

Is there any way to link the LOCATION_ID into LOCATIONS entity ,so when ever I access a trip(NSManagedObject) it automatically get LOCATIONS entity record (Object) ?

I mean automatically (Manually I can do that)

Thanks, Raghu

A: 

If I understand correctly your question, you simply need to model differently your entities in the Core Data model, as follows. In your TRIPS entity, add LOCATIONS as a relationship, not as a property as you currently do. The relationship may either be to-one or to-many from TRIPS to LOCATIONS, depending on the constraints you want to enforce in your application, and to-one from LOCATIONS to TRIPS.

Once you do this, when you fetch objects from the TRIPS entity, they will also contain a LOCATIONS object (if you decide to use a to-one relationships) or a set of LOCATIONS objects (if you decide for the to-many relationship).

unforgiven