iphone - Copying entities in Core Data -


i have couple of core data entities... student , exam.

now, exams 1 object per exam - maths exam 3, english exam 2 etc.

there relationship between students , exams in data model (a student can have several exams). initially, exams floating free, , not attached students.

how make copy of 1 of exams , attach student?

if like:

[student addexamsobject:examobject]; 

...then think references original exam student, rather making copy.

i need copy because exam has boolean 'hastaken', yes when student has taken exam. if set now, make seem students exam have taken it.

clarification: rather not restructure model. data taken couple of xml files, 1 each students , exams, parsed core data store. instance, exam object might this:

name:maths 5 class-id:12 year-id:4 student-id:0 

..with student object looking like

name: dave class-id:12 year=id:4 student-id:222 

various rules meant guide exams attached students... instance if exam's ids 0 students take exam. if class-id , year-id match, , student-id 0, exam gets added students same class , year. if student-ids match, student takes exam. etc etc. cannot change way xml outputted server.

another issue exam has too-many relationship question entity... in other words, questions in exam. , have store answers questions each student gives in exam.


edit: wish people try answer question rather tell me restructure whole program. there reasons why data model has been structured is.

edit2: maybe have restructure....

exam shouldn't have hastaken property. think in real world. exam not know has taken because many people have taken it. instance of taking exam, then, should first-class concept in model.

consider this:

exam has many takenexams, takenexams belongs student http://yuml.me/6627495d

now concept of taking exam real object, can model assocation metadata well, such datetaken, score, , on.

also remember core data expects have of inverse associations set well.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -