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

bhosted's avatar

Create multiple models using one join query

Just being curious, but is it possible to do one query, joining parent and grandparent tables, and create multiple model instances (child, parent and grandparent model) from the query result? It would save me 2 queries.

0 likes
2 replies
tykus's avatar

No.

How expensive are the queries that you think this optimisation is necessary?

bhosted's avatar

On each request it has to retrieve 3 different models for the authenticated user. I was just wondering if this could be optimized. But I guess the way to go is cache the authenticated user with these two extra models in one cache.

Please or to participate in this conversation.