patternMinor
Core Data model for test-taking iOS app
Viewed 0 times
coreiosappfortestdatamodeltaking
Problem
I'm building an iOS app for test-taking and I want to be sure of my model before proceeding.
I found this post very helpful and tried to implement a simplified version for Core Data.
Here are some of my assumptions:
Here is my Core Data model:
Overall, what do you think of my database schema? Is it sufficient to handle a simple test-taking app?
Here are my model headers for
Test_Questions.h
User_Answers.h
I found this post very helpful and tried to implement a simplified version for Core Data.
Here are some of my assumptions:
- Each
Usercan take multiple tests
- Each
Userhas one set of answers perTesttaken
- Each
Testhas oneUser
- Each
Questionhas many answers
Here is my Core Data model:
Overall, what do you think of my database schema? Is it sufficient to handle a simple test-taking app?
- Also, are
Test_QuestionsandUser_Answersnecessary?
- I could, in theory, have a relationship directly between
TestandQuestion?Test -->> Question.I would like to know which is better.
Here are my model headers for
Test_Questions and User_Answers:Test_Questions.h
@class Question, Test;
@interface Test_Questions : NSManagedObject
@property (nonatomic, retain) Test *test;
@property (nonatomic, retain) NSSet *questions;
@end
@interface Test_Questions (CoreDataGeneratedAccessors)
- (void)addQuestionsObject:(Question *)value;
- (void)removeQuestionsObject:(Question *)value;
- (void)addQuestions:(NSSet *)values;
- (void)removeQuestions:(NSSet *)values;
@endUser_Answers.h
@class Answer, User;
@interface User_Answers : NSManagedObject
@property (nonatomic, retain) User *user;
@property (nonatomic, retain) NSSet *userAnswersSet;
@end
@interface User_Answers (CoreDataGeneratedAccessors)
- (void)addUserAnswersSetObject:(Answer *)value;
- (void)removeUserAnswersSetObject:(Answer *)value;
- (void)addUserAnswersSet:(NSSet *)values;
- (void)removeUserAnswersSet:(NSSet *)values;
@endSolution
Test_Questions and User_Answers are not necessary since they do not hold any attribution and are one-to-one relationships with Test and User, respectively. It is always suspect when you have a plural table name.However, the model fails to support the ability of a
User to take multiple Tests. To fix that, User.testTaken should be replaced by User.testsTaken and made into a one-to-many relationship with Test.Also, it seems a bit odd that a
Test can only be taken by a single User, but if that's your requirement, then so be it.Context
StackExchange Code Review Q#64102, answer score: 2
Revisions (0)
No revisions yet.