Thomas Clayson
Thomas Clayson

Reputation: 29925

Core data database design issues

I want to create a core data model to store user input questions and then entries for those questions.

The questions will be 1 of 3 types. (1-10, Yes No or a number of specific units). So users will go into the app, click "add question" and will be shown a form where they will input the question title choose the question type (Yes/No, Scale 1-10 or Specific Units) - and if they choose specific units they have to put in those units eg: centimetres, millimetres, litres etc...

There will be multiple entries to these questions mapped over a period of time. IE: Users may put in the questions "How tall is your tomato plant? - specific units - CMs" and "How red are your tomatos? - scale 1-10" and will go back into the app time and again to map out the progress over time.

My question is about database design for this. How would I set this up in my core data?

At the moment I have this:

enter image description here

Now, I'm stuck! I don't quite know how to account for the fact that questions have different types, and therefore the entries will be different.

Plus I need to account for questions where units may be required. These are the questions that will just be a number.

So I'm thinking I probably need different question entites. Something like having a Questions entity and the specific questions as sub-entites - but I'm not sure how to do this, and not sure how to then record the entries made to those questions!

Thank you for looking, and for helping if you can. :)

Upvotes: 0

Views: 379

Answers (1)

bshirley
bshirley

Reputation: 8357

There's no correct way to design it, and there are indeed many different ways to design a solution.

As @dasdom suggested, you could remove the value from the Entry entity description, and make Entry abstract. Create three subclasses of Entry (BooleanAnswer, RankedAnswer, and ValueAnswer for example). The ValueAnswer would have a decimalValue and units, the others similar related values.

Also, FYI on naming conventions:

  • Entities: upper case, singular: Question and Entry (though i'd name it Answer)
  • Attributes/Relationships: lower case: questionText, type, entries, value, questions ('forQuestion' and 'forEntity' are redundant, being the relationship is defined on each of those)

Another option is to have Entity have units, boolValue, rankValue, and decimalValue but only use the attribute that's relevant. That's not an elegant solution, imho.

Upvotes: 1

Related Questions