Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can a many-to-many binary relationship have no intersection data?
I'm reading the book 'Fundamentals of Database Management Systems 2nd Edition' and in page 38, there is this question but the answer is not provided, just explain the many-to-many with an associative table!
short answer: yes, check page 129 for an example ;)
long one:
Intersection data are information that not belong to any of two entities of the M2M relationship, but they also don't describe the relationship.
I.e. Teachers and Students
A teacher can have many students, a student many teachers. The hours of lesson of each teacher with each student can be intersection data.
Hours
Teacher Student Hours
A 1 2
A 2 2
B 1 4
B 2 1
But we can also imagine this relationship without hours, for example if we are interested only in which students are in the class of each Teacher.
Classes
Teacher Student
A 1
A 2
B 1
B 2
This table continues to describe the relationship, but without intersection data.
Classes is the Associative Entity of the relationship Teacher - Student.
Hope this makes things a bit easier.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
It is obvious when to use a navigation property. But when should I use a inverse navigational property and when should I not use a inverse navigational property?
Should I always use a inverse navigation property when I use a navigation property to create a bi-directional relation?
Are there any guiding principles?
My guiding principle is to strive to keep things simple. I don't use them until I need them. :) Just like any other public member or method, (or any code for that matter) it should only exist if that existence is justified.
The presence of an inverse property indicates that I may treat that entity as a top-level and need to be able to refer to it's related entity. For example, a Customer contains Orders, so the question is should an Order reference back to it's Customer?
If I can query orders (irrespective of Customer) and want to be able to access customer information in those queries then it is beneficial to have an inverse property.
var orderDetails = context.Orders.Where(o => o.OrderDate == DateTime.Today)
.Select(o => new
{
o.OrderId,
o.OrderNumber,
CustomerName = o.Customer.Name
}).ToList();
As opposed to joining customer and order in a query to gain access to both customer and order details via a one-directional reference. (I tried writing an example from memory, but it got too ugly too fast. :D )
Where it doesn't make sense is to "always" have bi-directional references. For instance when you have something like an Address and an AddressType. AddressType will never need to know about a list of addresses of that type, and even if you did want to query that detail, it is easy enough to filter via the single-direction reference. It makes sense that Address (relative to the address type) is the top-level reference, where-as it makes sense that you may want to reference orders from a customer, or customer from an order.
They do not affect the generated sql. So from the point of view of database structure this is not important.
But when you are querying data from database by linq you can use that properties in "where" and "include" statements. So it gives you more options to create a query.
I'm almost always specifica inverse navigation property.
I'm still unsure whether I understand entity relationships. Just to confirm can I get someone to walk me through what I have created and confirm whether it is correct?
Data Model
So I'm creating a quiz app. This is my understanding of the above :
Category Entity - (e.g. geography) has a many to one relationship with QuizName. A single category can have multiple QuizNames.
A quizName (e.g. rivers in China) can have multiple Question entities. e.g. 'Which of one of these rivers are in China'
A Question can then have 4 possibleAnswers from which the person can choose from.
Have I made the data model correctly?
Thanks.
This model looks good, but Quiz seems better than QuizName.
If --->> is a one-to-many relationship:
Category --->> Quiz --->> Question
A Question entity could either have 4 String properties that represent answers or if each answer has specific attributes than maybe an answer should be yet another entity.
So i have done some research on Core data relationships with Swift, and i have a base understanding of the functionality, but i wanted to see if i could get some help on my specific model. What i want to do is get a user inputted question and answer and have that pair or pairs of questions and answers be saved to Core Data under a name. For the model, i was thinking i need to create a Questions entity with an attribute question, an Answers entity with an attribute answer and a Name entity with an attribute name. This is where i get confused on how i can make this work, or if it is even a correct model in order a deck name to be given, questions and answers be input and saved to that name only. Each time a new name is created, i want the new questions and answers to be saved to that name and so on. Thanks in advance for any help that can be given.
Name -->> Question (one to many relationship)
Question --> Answer (one to one assuming there's just one answer per q)
Then you need to create reverse relationships for all of the above.
This is how it should look like in the editor:
I have created a core data model that has two entities which have a one to many relationship. The entities are Exams and Questions. An Exam can have many questions.
What is the best way to save the Questions entities so they would be associated with the specific Exam?
The flow I want it to have is to start a new exam with an exam name, then add questions, then close out the exam with the questions count and save it to the persistent store.
After creating a Question object, just set its .exam property (provided that's the name of the inverse relationship to e.g. Exam.questions) to the containing exam object. If you need to order the questions, have a look at ordered relationships (available since Lion / iOS 5) or this or this.
I have two entities Company and Employees. Company has a 1-to-many relationship with employees. An almost exact question was asked here however it doesnt answer my question :(. Like in that question, xcode in Company.m generates 4 almost exactly the same methods. However, the prototypes are not included in Company.h which leads me to believe that this is either
An error and that company.h requires the 4 prototypes for the void functions described in.
Intended and those 4 methods are only usable in the .m file? If so how to add many employees to a company.
Standing by for any clarifications. Thanks!
Typically I just set the company on the employee when creating the employees.
[newEmployee setValue:company forValue:#"company"];
this will trigger the relationship both ways and add the employee to the companies set of employees.
or since you've subclassed it.
newEmployee.company = company;