3

Can anyone explains with an example for inverse relationship in apple core data?

Kara
  • 5,650
  • 15
  • 48
  • 55
Sridhar Bollam
  • 1,174
  • 1
  • 12
  • 19

4 Answers4

1

There's one simple explanation: http://brandontreb.com/core-data-quicktip-inverse-relationships/

JakubM
  • 2,587
  • 2
  • 19
  • 31
  • 2
    Links are not adequate for answers by themselves because they often lose their resources. Your link goes to a 404 error page. Please include the answer information in a quote from the link here. – Eric Mentele Jul 20 '16 at 19:55
1

(Better late than never)

When you have 2 or more entities then you can have a relationship. Say for example , there are 2 entities: Book and Publisher. We have a very simple relationship between them as:

Every book has a publisher and a publisher may publish many book.

(In coredata , relationship is not an entity like in RDBMS. Infact relationship is a part of 1 entity. Relationship between A and B in coredata means , A store the reference of another entity. So, when the managed object is created from the entity A,then relationship will become a property of any object created from entity A.)

In the above example, book to publisher is one-to-one relationship and from publisher-to-book is one-to-many. That means book and publisher has two way relationship no matter it's 1-to-1 or 1-to-many , this bidirectional relation is set to inverse in coredata.This kind of relation is known as inverse relation. If you set the book as a inverse to publisher then automatically publisher becomes inverse of book.

It's not technically essential but highly recommended by apple.If one is changed another is affected. What this let us do is keep the object graph more controlled and consistent.Most relationships are bidirectional like this.

Source: Lynda.com

Bikram Thapa
  • 1,269
  • 1
  • 16
  • 28
0

Definition from Google:

"in·verse ˈinvərs,inˈvərs

adjective 1. opposite or contrary in position, direction, order, or effect. "the well-observed inverse relationship between disability and social contact"

noun noun: inverse; plural noun: inverses 1. something that is the opposite or reverse of something else. "his approach is the inverse of most research""

What you are looking for from Apple:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/TroubleshootingCoreData.html#//apple_ref/doc/uid/TP40001075-CH26-SW1

"Core Data uses inverse relationships to maintain referential integrity within the data model. If no inverse relationship exists and an object is deleted, you will be required to clean up that relationship manually."

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/HowManagedObjectsarerelated.html

"Inverse Relationships

Most object relationships are inherently bidirectional. If a Department has a to-many relationship to the Employees who work in a Department, there is an inverse relationship from an Employee to the Department that is to-one. The major exception is a fetched property, which represents a weak one-way relationship—there is no relationship from the destination to the source. See Weak Relationships (Fetched Properties).

It is highly recommended that you model relationships in both directions, and specify the inverse relationships appropriately. Core Data uses this information to ensure the consistency of the object graph if a change is made (see Manipulating Relationships and Object Graph Integrity)."

A great example is the second answer here and it should be upvoted:

Does every Core Data Relationship have to have an Inverse?

Community
  • 1
  • 1
Eric Mentele
  • 754
  • 8
  • 15
-3

Try this (First google result for 'Core Data relationship tutorial iphone') :

http://www.raywenderlich.com/934/core-data-tutorial-getting-started

deanWombourne
  • 37,003
  • 13
  • 93
  • 99
  • There's no explanation in the link, I myself came here from this tutorial to find out what inverse relationship is ;o) – JakubM Oct 07 '12 at 12:07
  • The reason I mentioned Google should have been a hint for your next step in finding the answer . . . ;) – deanWombourne Oct 08 '12 at 10:29