@@ -10,29 +10,27 @@ trait AutoSet
1010 *
1111 * @return void
1212 */
13- public function setFromDb ()
13+ public function setFromDb ($ setFields = true , $ setColumns = true )
1414 {
1515 if ($ this ->driverIsSql ()) {
1616 $ this ->getDbColumnTypes ();
1717 }
1818
19- array_map (function ($ field ) {
20- $ new_field = [
21- 'name ' => $ field ,
22- 'label ' => $ this ->makeLabel ($ field ),
23- 'value ' => null ,
24- 'default ' => isset ($ this ->autoset ['db_column_types ' ][$ field ]['default ' ]) ? $ this ->autoset ['db_column_types ' ][$ field ]['default ' ] : null ,
25- 'type ' => $ this ->inferFieldTypeFromDbColumnType ($ field ),
26- 'values ' => [],
27- 'attributes ' => [],
28- 'autoset ' => true ,
29- ];
30-
31- if (! isset ($ this ->fields ()[$ field ])) {
32- $ this ->addField ($ new_field );
19+ array_map (function ($ field ) use ($ setFields , $ setColumns ) {
20+ if ($ setFields && ! isset ($ this ->fields ()[$ field ])) {
21+ $ this ->addField ([
22+ 'name ' => $ field ,
23+ 'label ' => $ this ->makeLabel ($ field ),
24+ 'value ' => null ,
25+ 'default ' => isset ($ this ->autoset ['db_column_types ' ][$ field ]['default ' ]) ? $ this ->autoset ['db_column_types ' ][$ field ]['default ' ] : null ,
26+ 'type ' => $ this ->inferFieldTypeFromDbColumnType ($ field ),
27+ 'values ' => [],
28+ 'attributes ' => [],
29+ 'autoset ' => true ,
30+ ]);
3331 }
3432
35- if (! in_array ($ field , $ this ->model ->getHidden ()) && ! in_array ( $ field , $ this ->columns ())) {
33+ if ($ setColumns && ! in_array ($ field , $ this ->model ->getHidden ()) && ! isset ( $ this ->columns ()[ $ field ] )) {
3634 $ this ->addColumn ([
3735 'name ' => $ field ,
3836 'label ' => $ this ->makeLabel ($ field ),
0 commit comments