4

I have a site that has these different types of content:

  • Candidates
  • Questions
  • Answers

So there's a list of questions, that have answers that are related to a candidate. I imagine the models look like:

Question

  • Question Info

Answers

  • relatedCandidate
  • relatedQuestion

Candidate

  • Candidate Info

The main question is is this the best setup for this particular situation? Or should I have a matrix in Questions with all the answers and then a related field for the candidate and the answer?

While this works if the question section works on it's own, if I ever need to display candidates and then their corresponding answers, I don't know if I can run through the Questions' matrix field and find only that candidate's answer.

3

I think this is the best way to model the data, and it lends itself very well to how Craft work.

I guess the only reason to go with the Matrix approach instead, would be to ease how the information is published in the control panel. In some cases it might be easier to just publish one question with all the answers, instead of one question and all the answers seperately. But it's hard to say, not knowing the actual content and amount of data.

It would definitely be possible to go for the Matrix solution too, but it might be a bit more complex to use in your templates, and maybe less efficient. But again, depends on your actual case.

2
  • 1
    +1 on this approach. As a side note, you might want to check out a nice plugin called introvert so that you can display the reverse related answers on the question entry in the CP (for display and easy linking only). Feb 20 '15 at 22:07
  • Yeah, I tried to do a trail run using the matrix fields and it's kind of crazy to pull in that manner. But I do see how it'd be easier to enter in the data all at once. Feb 21 '15 at 14:03
1

Personally I wouldn't relate questions and answers from the answer, I'd relate them from the question.

If I understand your concept here, questions might have more than one answer, but an answer can't answer more than one question?

If that's the case, I'd set up 3 channels:

  • Questions
  • Answers
  • Candidates

And in your Questions channel, I'd have a relatedAnswers entry field, so answers can be assigned that way.

Everything else I'd keep the same as you have suggested, but with a relatedAnswers field, relatedQuestion would no longer be needed.

You have to also remember that a Candidate might answer more than one question. So having their information in a matrix field on the answer entry would mean a lot of repeated data.

Set up a Candidates channel with entries for each candidate, and add a relatedCandidates entry field to your answer entries so the candidate(s) can be assigned that way.

2
  • 1
    What are the benefits on having a relatedAnswers field on Question, instead of a relatedQuestion field on an Answer? The way I see it, this would just make it more work to publish an Answer. You'd have to publish the Answer entry, then find the Question entry, and then find and add the Answer you created to the relatedAnswers field. Instead of just publish the entry. Since an Answer is related to only one Question, I don't really see the benefit. Feb 20 '15 at 15:38
  • @AndréElvan Yeah that's a fair point. I guess, as you said in your answer it comes down to the amount of content for answers. It's hard to say without the specifics.
    – Jamie Wade
    Feb 20 '15 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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