How to store data of a nested repeater field with relationships?
Hi there,
I'm building an exam management module and I'm trying to figure out how to store data for a nested repeater field. The repeater field is called "Questions", and it allows the user to create multiple questions for an exam test. Each question has a text field and a nested repeater field called "Options", which allows the user to create multiple options for that particular question.
Here's my question: how can I store the data for the nested repeater field with relationships? Specifically, I want to store the exam test data in the exam test table, the questions in the questions table, and the options in the options table. In the questions table, I have an 'exam_test_id' column which references the id of the test, and in the options table, I have a 'question_id' column that references the id of the question.
Do I need to apply a relationship to the respective repeaters in my Exam Test form? And how would I go about storing the data for each nested repeater with the appropriate relationships?
Any help would be greatly appreciated. Thank you in advance!
5 Replies
Repeater has a relationship() method
you can nest them just fine
try it
it is documented
Thank you for your response. I have tried passing a relationship named "questions" to the relationship() method in the ExamTest model but unfortunately, I'm getting an SQL database error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sort' in 'order clause'". However, when I remove the relationship from the relationship() method, the page loads just fine. I am not sure what could be causing this error as the "sort" column is not explicitly mentioned in my code. Do you have any suggestions on how I can resolve this issue?
These are the models
youre probably using reordering on that repeater so you need a column to store the sort
It works now. Thank you