I’m working on a little PHP Framework for a school project and I’m currently learning how to build the ORM part.
However, I can’t figure out how to map object relationships from a SQL query with joins or I just don’t know the right words to search 🙁
t1
id
title
text
–
t2
id
name
description
I tried to do a simple : SELECT * FROM t1 LEFT JOIN t2 ON t1.id = t2.t1_id
What I get is a simple array with all the fields from both tables and id column gets overridden as It exist in both.
[
"id" => "2"
"title" => "Lorem"
"text" => "Ipsum"
"name" => "Tomato"
"description" => "Tomato are nice"
]
So my question is there a simple way to get something like this with joins ?
[
"t1" => [
"id" => 2
"title" => "Lorem"
"text" => "Tomato"
"t2" => [
"id" => 3
"name" => "Tomato"
"description" => "Tomato are nice"
]
]
No, a join is for creating a table view of the two tables side to side. But you can do:
Which will give you prefixes like:
That solves the same problem you were trying to solve.