]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/table.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Feb 2018 22:32:01 +0000 (22:32 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Feb 2018 22:32:01 +0000 (22:32 +0000)
lib/php/db/table.php

index 8bc0abf98f14d97e42923bc65900216ab3f4e84a..6df037ce9342a9f3ee9db6de5c6b53b6421ddc82 100644 (file)
@@ -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 .= '<td class="action">'.$buttons[0].'</td>'.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 .= '<td'.$this->__rows_table_attr[$k].'>'.$v.'</td>'.NB_EOL;