← Back to team overview

anewt-developers team mailing list archive

[Bug 361805] [NEW] Incorrect NULL values on left joins in AutoRecord

 

Public bug reported:

When using AutoRecord::_db_join_one() for a left join (default) and the right side doesn't exist, the key will be overwritten with NULL values. Example:
Table1:
+--+-----+
|id|name1|
| 1|foo1 |
| 2|foo2 |
+--+-----+

Table2:
+--+-----+
|id|name2|
| 1|bar1 |
+--+-----+

> SELECT t1.id, t1.name, t2.id, t2.name FROM table1 t1 LEFT JOIN table2 t2 ON (t1.id = t2.id)
+--+-----+--+-----+
|id|name1|id|name2|
+--+-----+--+-----+
| 1|foo1 | 1|bar1 |
| 2|foo2 |  |     |
+--+-----+--+-----+

This will result in the following data structure:
$data = array(
  array(
    'id' => 1,
    'name1' => 'foo1',
    'name2 => 'bar1',
  ),
  array(
    'id' => NULL
    'name1' => 'foo2',
    'name2' => NULL
  ),
)
This is because the second 'id' overwrites the first one.

** Affects: anewt
     Importance: Undecided
         Status: New

** Description changed:

  When using AutoRecord::_db_join_one() for a left join (default) and the right side doesn't exist, the key will be overwritten with NULL values. Example:
  Table1:
  +--+-----+
  |id|name1|
  | 1|foo1 |
  | 2|foo2 |
  +--+-----+
  
  Table2:
  +--+-----+
  |id|name2|
  | 1|bar1 |
  +--+-----+
  
  > SELECT t1.id, t1.name, t2.id, t2.name FROM table1 t1 LEFT JOIN table2 t2 ON (t1.id = t2.id)
  +--+-----+--+-----+
  |id|name1|id|name2|
  +--+-----+--+-----+
  | 1|foo1 | 1|bar1 |
  | 2|foo2 |  |     |
  +--+-----+--+-----+
  
  This will result in the following data structure:
  $data = array(
    array(
      'id' => 1,
      'name1' => 'foo1',
      'name2 => 'bar1',
    ),
    array(
      'id' => NULL
-     'name1' => 'foo1',
+     'name1' => 'foo2',
      'name2' => NULL
    ),
  )
  This is because the second 'id' overwrites the first one.

-- 
Incorrect NULL values on left joins in AutoRecord
https://bugs.launchpad.net/bugs/361805
You received this bug notification because you are a member of Anewt
developers, which is subscribed to Anewt.



Follow ups

References