Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

I'm not seeing a question here. Lol. Do you want to return both AnswerChoices and MatchingQAnswerChoices?

Last updated 9 years ago.
0

Question Model have ONE TO MANY relation-ship with AnswerChoice and MatchingQAnswerChoices. At a time either AnswerChoice or MatchingQAnswerChoices will point to Question,not both.

I have defined relation is below:-

public function AnswerChoices()
{
if($this->question_type_id =='5')
return $this->hasMany('App\MatchingQAnswerChoices');
else
return $this->hasmany('App\AnswerChoice','question_id');
}

But this relationship never returns MatchingQAnswerChoices data even if Question_Type=5.

Is there another approach to get data in this type of scenario?

Last updated 9 years ago.
0

thomastkim said:

I'm not seeing a question here. Lol. Do you want to return both AnswerChoices and MatchingQAnswerChoices? Yes. If I am using below code, its nor returning MatchingQAnswerChoices only AnswerChoices .

 $quiz = App\Quiz::with('sections.questions.AnswerChoices');
0

Have you tried this?

$quiz = App\Quiz::with('sections.questions.AnswerChoices', 'sections.questions. MatchingQAnswerChoices')->where(['created_by'=>\Auth::user()->id, 'id' => $id])->get();
Last updated 9 years ago.
0

thomastkim said:

Have you tried this?

$quiz = App\Quiz::with('sections.questions.AnswerChoices', 'sections.questions. MatchingQAnswerChoices')->where(['created_by'=>\Auth::user()->id, 'id' => $id])->get();

Thanks for reply.Yes I am using this approach. But is it effective way? I mean is this best approach or we can tweak our Model Relationship bit more?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.