CPgsqlColumnSchema:
--- 53,60 ----
$this->defaultValue=$this->typecast(str_replace("''","'",$matches[1]));
else if(preg_match('/^-?\d+(\.\d*)?$/',$defaultValue,$matches))
$this->defaultValue=$this->typecast($defaultValue);
+ else if(strpos($defaultValue, '(') === 0)
+ $this->defaultValue=$this->typecast(new CDbExpression($defaultValue));
// else is null
}
}
CActiveRecord:
@@ -2282,17 +2282,8 @@
foreach($table->columns as $name=>$column)
{
- if(!$column->isPrimaryKey && $column->defaultValue!==null)
- $this->attributeDefaults[$name]=$column->defaultValue;
+ if(!$column->isPrimaryKey) {
+ if ($column->defaultValue instanceof CDbExpression) {
+ $result = Yii::app()->db->createCommand('SELECT ' . $column->defaultValue->expression . ';')->queryColumn();
+
+ if (isset($result[0]))
+ $this->attributeDefaults[$name]=$result[0];
+ }
+ else if ($column->defaultValue!==null)
+ $this->attributeDefaults[$name]=$column->defaultValue;
+ }
}
foreach($model->relations() as $name=>$config)