Last active
December 19, 2015 13:18
-
-
Save lantian/5960738 to your computer and use it in GitHub Desktop.
Phalcon createTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($this->_getModels() as $model) { | |
$columns = array(); | |
$primaries = array(); | |
foreach ($model['columns'] as $columnName => $column) { | |
if (isset($column['is_primary']) && $column['is_primary']) { | |
$primaries = $columnName; | |
} | |
$columns[] = new Column( | |
$columnName, | |
array( | |
"type" => $column['type'], | |
"size" => (isset($column['size']) ? $column['size'] : false), | |
"notNull" => (isset($column['nullable']) ? $column['nullable'] : false), | |
(isset($column['identity']) && (isset($column['is_numeric']) && $column['is_numeric']) ? "autoIncrement" : null) => true, // error in Phalcon, when autoIncrement is false for 'string' type | |
"primary" => (isset($column['is_primary']) ? $column['is_primary'] : false), | |
"isNumeric" => (isset($column['is_numeric']) ? $column['is_numeric'] : false), | |
) | |
); | |
} | |
$connection->createTable($model['name'], null, array( | |
"columns" => $columns, | |
"indexes" => array(new Index("PRIMARY", array($primaries))) | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment