catfan / Medoo

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

Mapping tables with same column names does not work #449

Closed piotrostrowski closed 3 years ago

piotrostrowski commented 8 years ago

Hello, I have encountered an issue while using the new mapping function. Whenever there is a joining table with same column names medoo will put null values into those fields. Example:

$artworks = $db->select('artworks', [
      '[>]author' => ['id_author' => 'id']
 ], [
      'artworks.id',
      'artworks.created_at',
      'artworks.modified_at',
      'author' => [
        'author.id',
        'author.name',
        'author.created_at',
        'author.modified_at'
 ], $where);

Is there any way to avoid this issue?

catfan commented 8 years ago

You can use alias feature to prevent the conflict right now.

[
      'artworks.id',
      'artworks.created_at',
      'artworks.modified_at',
      'author' => [
            'author.id(author_id)',
            'author.name',
            'author.created_at(author_create)',
            'author.modified_at(author_modified)'
      ]
]

if don't use the data mapping, it is still require you to use the alias to identify the conflicted column.

[
      'artworks.id',
      'artworks.created_at',
      'artworks.modified_at',
      'author.id(author_id)',
      'author.name',
      'author.created_at(author_create)',
      'author.modified_at(author_modified)'
]

But it will be a little bit complex to handle this without using the alias, because Medoo is using PDO::FETCH_ASSOC to fetch the data, it can be improve for it in the further.

piotrostrowski commented 8 years ago

Thanks @catfan for the reply! Unfortunately aliases does not work within those internal mappings. Following piece of code results in: NOTICE: Undefined index: id(author_id)

catfan commented 8 years ago

@piotrostrowski Well, it is a bug. We missed handle the alias for internal mapping. And we fixed it now.

ideerge commented 4 years ago

really need a solution without the alias