Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data inverse relation

Tags:

core-data

What is an example of an inverse relationship in Apple's Core Data framework?

like image 720
Sridhar Bollam Avatar asked May 29 '26 21:05

Sridhar Bollam


1 Answers

(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

like image 82
Bikram Thapa Avatar answered Jun 02 '26 20:06

Bikram Thapa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!