catfan / Medoo

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

Index Mapping with Join #864

Closed Hashiyama89 closed 5 years ago

Hashiyama89 commented 5 years ago

Describe the bug When you use a join query, and want to map one field which exists in both tables, it doesn't work.

Information

Detail Code

If I do this, they cant find the index mappin 'books.id' $result = $this->select( ['[>]photos' => ['id' => 'photo_id']] , [ 'books.id' => [ 'books.id [Int]', 'name', 'url' ]], ["books.id" => $ids]);

In this case, the field ID exists in photos and books, so the query crash. $result = $this->select( ['[>]photos' => ['id' => 'photo_id']] , [ 'id' => [ 'books.id [Int]', 'name', 'url' ]], ["books.id" => $ids]);

catfan commented 5 years ago

This is a bug and fixed it on cf25af9.

However, when joining table, all those column name should be with table name as prefix.

$this->select([
    '[>]photos' => ['id' => 'photo_id']
], [
    'books.id' => [
        'books.id [Int]',
        'photos.name',
        'photos.url'
    ]
], [
    "books.id" => $ids
]);