diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index c93925a..348fa95 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -23,6 +23,8 @@ class DoubleField extends PhangoField { $this->size=$size; $this->form='PhangoApp\PhaModels\Forms\BaseForm'; + $this->value=0; + $this->default_value=0; } diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 973fc05..de8dc41 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -42,6 +42,7 @@ class ForeignKeyField extends IntegerField{ $this->protected=0; //($name, $value, $model, $field_name, $field_value) $this->parameters=array($this->related_model, $name_field, $this->related_model->idmodel); + $this->default_value='NULL'; } diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index a8e8ceb..aaefe69 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -29,6 +29,7 @@ class IntegerField extends PhangoField { $this->max_num=$max_num; $this->quot_open=''; $this->quot_close=''; + $this->default_value=0; } diff --git a/src/CoreFields/MoneyField.php b/src/CoreFields/MoneyField.php index f6b55aa..608845e 100644 --- a/src/CoreFields/MoneyField.php +++ b/src/CoreFields/MoneyField.php @@ -14,6 +14,7 @@ class MoneyField extends DoubleField{ parent::__construct(11, true, 0, 0); $this->form='PhangoApp\PhaModels\Forms\MoneyForm'; + $this->default_value=0; } diff --git a/src/CoreFields/SerializeField.php b/src/CoreFields/SerializeField.php index 8ef46df..b515f48 100644 --- a/src/CoreFields/SerializeField.php +++ b/src/CoreFields/SerializeField.php @@ -26,6 +26,7 @@ class SerializeField extends PhangoField { { $this->related_type=$related_type; + $this->default_value='{}'; } diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index ba2d1c1..b30d423 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -23,6 +23,7 @@ class TextField extends PhangoField { $this->form='PhangoApp\PhaModels\Forms\TextAreaForm'; $this->multilang=$multilang; + $this->default_value=''; } @@ -74,4 +75,4 @@ class TextField extends PhangoField { } } -?> \ No newline at end of file +?> diff --git a/src/Webmodel.php b/src/Webmodel.php index 300bbc4..d0d0376 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -680,8 +680,12 @@ class Webmodel { { //Foreach for create the query that comes from the $post array - - foreach($fields as $key => $field) + + $components=$this->components; + + unset($components[$this->idmodel]); + + foreach($components as $key => $field) { $quot_open=$this->components[$key]->quot_open; @@ -699,12 +703,23 @@ class Webmodel { $fields[$key]='NULL'; } } - - $arr_fields[]=$quot_open.$fields[$key].$quot_close; + + if(!isset($fields[$key])) + { + + $arr_fields[]=$quot_open.$this->components[$key]->default_value.$quot_close; + + } + else + { + + $arr_fields[]=$quot_open.$fields[$key].$quot_close; + + } } - return 'insert into '.$this->name.' (`'.implode("`, `", array_keys($fields)).'`) VALUES ('.implode(", ",$arr_fields).') '; + return 'insert into '.$this->name.' (`'.implode("`, `", array_keys($components)).'`) VALUES ('.implode(", ",$arr_fields).') '; }