F
Filament15mo ago
Homd

Is it possible to get the future id of item in repeater?

I have: Question Model: - id - name - correct_answer -> references id on Question_Answers Question_Answer Model: - id - answer - question_id I want to use repeater to create question and its answer in single modal. Is there anyway I could access to-be-created Question_Asnwer and assign in to my Question's correct_answer? What's the best approach here? Thanks!
6 Replies
wyChoong
wyChoong15mo ago
is this something like a question with multiple answer options and you want to tag which is the correct answer to the question? you probably want to have is_correct in your answer model and use a toggle in your repeater as it makes more sense there, and what if you have multiple choices answer when more than 1 option can be correct
Homd
HomdOP15mo ago
@wyChoong Yes, that is my first thought. But here each question only have one correct answer plus I want to see if it's actually possible for other use cases as well.
wyChoong
wyChoong15mo ago
Even though if it’s not, it’s easier to manage the correct at the answer level In my opinion, it’s up to you You definitely can have the correct answer at the question, just add a select dropdown to the question form
Homd
HomdOP15mo ago
But the answer is not created yet before the submit button is press, how do I get the future id of it? Actually, yes I agree its better. Sadly asking for a database change require some extra work. I can't change it by myself, it's the other party that need to change it.
wyChoong
wyChoong15mo ago
can't think of a safe way of doing it, because you can't get a future id of a record so it will be 2 step process, after creating the question and answers, show the select dropdown in question edit form to select and save
Homd
HomdOP15mo ago
Oof, ok thanks for trying to help
Want results from more Discord servers?
Add your server