From: Nicolas Boisselier Date: Wed, 7 Feb 2018 22:32:01 +0000 (+0000) Subject: lib/php/db/table.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=628933914a2883704583ad660fcc86bfb73b2c9e;p=nb.git lib/php/db/table.php --- diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 8bc0abf9..6df037ce 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -913,7 +913,7 @@ Class Table extends nb { if ($v === false or $v === null) { if (isset($this->fields[$k])) unset($this->fields[$k]); #if (isset($this->extras[$k])) unset($this->extras[$k]); - $this->_rows_fields = true; + $this->_add_extras = true; continue; } @@ -968,7 +968,7 @@ Class Table extends nb { $select_count = ( $where ? $this->db()->conf_type('select_count') : null ); if (empty($select_count)) $select_count = ['','']; - if (!empty($this->_rows_fields)) { + if (!empty($this->_add_extras)) { foreach ($this->fields() as $f) { if (empty($f->extra)) $select_fields[] = $f->sql_name(); } @@ -1035,9 +1035,13 @@ Class Table extends nb { } // - // Fields filter + // Fields filter / Add missing // - $this->fields_only($row,array_keys($opt['fields'])); + $new = []; + foreach ($opt['fields'] as $k=>$f) { + $new[$k] = isset($row[$k]) ? $row[$k] : null; + } + $row = $new; // // Format @@ -1049,6 +1053,11 @@ Class Table extends nb { } + // + // Keep only wanted fields + // + $this->fields_only($row); + // // Post // @@ -1099,12 +1108,6 @@ Class Table extends nb { $this->db()->type = $opt['db_type_from']; } - # - # Fields - # - $opt['fields'] = $fields = $this->fields(); - $this->fields_only($fields); - # # Build query # @@ -1157,6 +1160,12 @@ Class Table extends nb { } # < nosql + # + # Fields + # + $opt['fields'] = $fields = $this->fields(); +# NB 07.02.18 $this->fields_only($fields); + # Check fields_only exists if (!empty($this->fields_only)) foreach ($this->fields_only as $f) { if (!$this->field($f)) $this->bye("Unknown field ".$f); @@ -1599,7 +1608,7 @@ Class Table extends nb { if ($this->buttons() and !empty($buttons[0])) $html .= ''.$buttons[0].''.NB_EOL; foreach ($row as $k => $v) { - if ( !empty($this) and !empty($this->field($k)) ) { + if ( !empty($this->field($k)) ) { $v = $this->field($k)->htmlValue($v); } $html .= '__rows_table_attr[$k].'>'.$v.''.NB_EOL;