Skip to content

Commit

Permalink
Fixes #224: Add default validator with null value for integers when d…
Browse files Browse the repository at this point in the history
…b is PostgreSQL
  • Loading branch information
MaksimKiselev authored and samdark committed Jan 30, 2017
1 parent 1cb0dc2 commit 397c3fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 gii extension Change Log
2.0.6 under development
-----------------------

- Bug #224: Add default validator with null value for integers when db is PostgreSQL (MKiselev)
- Enh #223: Use ilike operator when generating search model for PostgreSQL (MKiselev)
- Enh #241: Remove message for unique validator (MKiselev)
- Enh #238: Use int/bool instead of integer/boolean in phpdoc blocks generated (MKiselev)
Expand Down
15 changes: 15 additions & 0 deletions generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ public function generateRules($table)
}
}
$rules = [];
$driverName = $this->getDbDriverName();
foreach ($types as $type => $columns) {
if ($driverName === 'pgsql' && $type === 'integer') {
$rules[] = "[['" . implode("', '", $columns) . "'], 'default', 'value' => null]";
}
$rules[] = "[['" . implode("', '", $columns) . "'], '$type']";
}
foreach ($lengths as $length => $columns) {
Expand Down Expand Up @@ -888,6 +892,17 @@ protected function getDbConnection()
return Yii::$app->get($this->db, false);
}

/**
* @return string driver name of db connection.
* @since 2.0.6
*/
protected function getDbDriverName()
{
/** @var Connection $db */
$db = $this->getDbConnection();
return $db->driverName;
}

/**
* Checks if any of the specified columns is auto incremental.
* @param \yii\db\TableSchema $table the table schema
Expand Down

0 comments on commit 397c3fd

Please sign in to comment.