Pergunta

Below is an illustration of the kind of data I want to save in Core data. Every city has many schools , every school has many grades and every grade has many students and their details.

I have read a couple of things about Core data and have got it up and starting. But I'm not able to understand how to save an array in core data and is it a good way to do that in the similar case of the illustration?

If i want to save for a particular school an array of total students for that particular grade, would it be a good practice? If yes, is the method provided in this link good to follow?

enter image description here

EDIT : All cities, all schools and all students have same attributes. Whereas each grade has different attributes. So if there are data for 10 grades, there may be 10 types of array for grades.

Also, what if i have a one to many relation between school and students? IE depending on my login i decide whether i need to save school and grades or school and students. How would the relationship be now?

Foi útil?

Solução

You should use core data with one to many relationship. Thisenter image description here would be your entity structure.

UPDATE: In case you have several grades with different attributes, you can define another entity "GradeType", which contains details of each grades like this:

UPDATE 2:

Let me write down considerations in this scenario.
1. A city can have multiple schools in it, but a school can be only in one city (Branches will have different address ;) ).
2. A school may offer multiple subjects. same subject can be taught in multiple cities.
3. A school may contain multiple students while a student can be enrolled only in one school.
4. A student can register for multiple subjects, while same subject can be registered by multiple students.
5. There can be multiple grades possible for a subject.(lets say 4: A, B, C & D). Similarly, many subjects will follow the same grading system.(A in history, B in Geology etc).
6. A student can have multiple grades. However, the number of grades will be equal to number of subject he/she opted for.

Based on above consideration, this would be your dataModel.image

Here Grades Entity will have entries like this:
grade A for physics is scored by these students.
grade A for biology is scored by these students.

grade B for physics is scored by these students.
grade B for biology is scored by these students.
… … N So on

Let me know if more info needed.

Outras dicas

Dont do it the way shown in that link. Create core data entities for each of them (city,school,grade,student). Add relationship between those entities (Eg: City ->> school which means one to many relationships). Check this link http://www.raywenderlich.com/14742/core-data-on-ios-5-tutorial-how-to-work-with-relations-and-predicates. Refer apple document https://developer.apple.com/library/mac/documentation/cocoa/conceptual/coredata/articles/cdRelationships.html as well. Take your time with core data modelling. Hope it helps

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top