Here above shows the ER-Diagram.
It's easy to implement to-many binary relationship using core data. But it confuse me how to implement this kind of multiple relationship.
Hope that someone could give a hand.
I am not sure if I understood your problem correctly, but wouldn't two
one-to-many relationships (from Course to TA and from Student to TA) describe
your model? Each TA has exactly one Student and one Course, but each Student and
each Course can be related to many TAs.
Related
I need your advices on how to realise the following model in entity framework core 2.x :
I would like to implement a kind of “favorite” functionality in our software system where a user can mark customers, orders, messages etc. as “favorite” because the user is working on them right now and wants to have them in a list for quick access. Is there a possibility to realise this kind of relationship - where m can be of different types (customer, order, message …) with one relation table?
Thanks a lot for any feedback !
Best regards,
Fabianus
I have category entity and subcategory entity. I need to get subcategory data to that related categoryId of category entity.
My category entity contains these attributes: "categoryId","categoryName"
subcategory contains: "subcategoryId","subcategoryName", "categoryId".
So can any one please guide me how can i put the relationship between this two entity ??
Thanks for advance.
Very first you are mixing the concepts of MySQL or SQLite with Core data. Unlike them Core Data does not have primary-foreign Key concept to relate entities(for easy understanding tables in MySQL). Just create relationship between those entities and you can fetch data their data.
Now about your Entities you have are category and subcategory. So you have to create relationship between them. If one category have many subcategories you have to check To many relationship option from Data Model Inspector..Otherwise One to One relationship would be the one you should go for..Have a look at screenshot how you can make your relationship one to many..
This is a good tutorial link for one to many relationship. You can refer if you do not know how to implement.
Also this for tutorial simple relationship in Core Data..
if you are beginner with Core data you can go with Quick Tutorial Start by Apple and you will get basic idea of Core data.
I am new to the core data and am loving it so far, I just have a question on to-many relations and their inverses. I'm trying to create something where each unit can convert to many other units so each unit can point to many converters that point to just one other unit. The image below works perfectly, but I know that core data wants them to be inverse and lets me know. When I try to select this it eliminates the functionality I desire.
I have tried creating a new relationship on each entity to act like an inverse but it fails, I can get a set of null objects.
Basically I am trying to create a graph-like structure in core data.
Is it possible to get this functionality while making core data happy with supplying inverses?
You should be able to make inverses by adding a relationship to each entity. The Converter entity would get a ConvertsFrom to-one relationship which is inverse to the Converters relationship, and Unit would get a ConvertedBy to-many relationship (since it can be converted by many converters) which is inverse to the ConvertsTo relationship.
Say you have a couple of Core Data entities .. Student and Exam. These two are initially filled with data from two xml files downloaded from the web.
Now, Students and Exams are separate things... initially there are no connections between them. But after filling out these two entities, I might want to connect certain students to certain exams. Or I might want make all students take a particular exam. But I still want to be able to treat Exams as independent things, which might have no students connected.
I'm unsure how to do this with Core Data. In the data model, you either have a relationship or yo don't. Should I have two different entities for Exam... one for independent exams, and one connected to the student which can be built up from the other Exam enitity?
No, you should not make two entity types.
Just because you have a relationship between two kinds of entities doesn't mean you can't create an object where that relationship is nil.
So, assuming you have a many-to-many relationship between Student and Exam, you might create a new exam by doing something like:
Exam *newExam = [NSEntityDescription
insertNewObjectForEntityForName:#"Exam"
inManagedObjectContext:context];
newExam.course = #"CS 101";
newExam.description = #"Midterm";
You might then later establish a relationship between a student and that exam like:
[newExam.students addObject:aStudent];
(where students is the name of the relationship between Exam and Student
I think you should have a relationship between the two entities (exam and student) but mark it as optional.
If a Core Data relationship has an inverse relationship do you only need to set one of the relationships objects then the corresponding relationship is setup?
In the past I have set both relationships but when looking at iPhone Core Data Recipes it seems they only set 1 of the relationships?
Thanks
James
I found the answer in the documentation:
Since Core Data takes care of the object graph consistency maintenance for you, you only need to change one end of a relationship and all other aspects are managed for you. This applies to to-one, to-many, and many-to-many relationships. Consider the following examples.
So the answer is YES you only need to set one side of the relationship.
More information here:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html#//apple_ref/doc/uid/TP40001857-CJBDBHCB