Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

randm's avatar

How to create hasManyThrough?

I have an object called SurveyInterview. This Object has a field called "current_step_id"

I have another object called SurveyUsedQuestions which have a column called question_id and a column called step_id.

Finally I have a third object called SurveyQuestions.

I need to add a hasManyThrough onto my SurveyInterview object which will allow me to access the questions object.

If I was to represent what I need with a query I would do this

SELECT questions.*
FROM interviews
INNER JOIN used_questions ON used_questions.step_id = interview.current_step_id 
INNER JOIN questions ON question_id = used_questions.question_id

if hasManyThrough relation the right was to do this or is there another way I would need to do to build this relation?

0 likes
4 replies
pmall's avatar

This is not a hasManyThrough relationship, it is a belongsToMany relationship with used_questions as pivot table.

Please or to participate in this conversation.