catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Select Join data mapping ID issue #861

Closed tipleavalentin closed 3 years ago

tipleavalentin commented 5 years ago

Describe the bug I'm trying to join two tables and get the content in an array (mapped data) but the first table ID is wrong.

Information

Expected output What I should get as result is this: { "id": 71, "compartment": { "id": 15 } }

But I get a wrong result which is this: { "id": 15, "compartment": { "id": 15 } }

So basically the id of the compartment is replaced by the id of the compartment_units record.

tipleavalentin commented 5 years ago

Note: if I don't select the ID column from the second table then the first table ID is correct.

catfan commented 5 years ago

It will be conflicted if you are joining two table with same alias name.

So change the joined table column alias as possible

"compartments.id (id) [Int]",
"compartment": [
    "compartment_units.id (unit_id) [Int]",
]

It is an idea may make this possible for that, but it need more complex process for handling fetched data and slow down the speed. I may try for it.