5
\$\begingroup\$

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:

  • Each User can take multiple tests
  • Each User has one set of answers per Test taken
  • Each Test has one User
  • Each Question has many answers

Here is my Core Data model:

enter image description here

Overall, what do you think of my database schema? Is it sufficient to handle a simple test-taking app?

  • Also, are Test_Questions and User_Answers necessary?
    • I could, in theory, have a relationship directly between Test andQuestion? 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;

@end

User_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;

@end
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.