Skip to content

Commit 6c511d9

Browse files
authored
Fix #19759: Update docs for Command::createTable(), Migration::createTable() and QueryBuilder::createTable()
1 parent 94a1cc5 commit 6c511d9

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

framework/db/Command.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,24 @@ public function delete($table, $condition = '', $params = [])
631631
*
632632
* The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'),
633633
* where name stands for a column name which will be properly quoted by the method, and definition
634-
* stands for the column type which can contain an abstract DB type.
634+
* stands for the column type which must contain an abstract DB type.
635+
*
635636
* The method [[QueryBuilder::getColumnType()]] will be called
636637
* to convert the abstract column types to physical ones. For example, `string` will be converted
637638
* as `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
638639
*
639640
* If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
640641
* inserted into the generated SQL.
642+
*
643+
* Example usage:
644+
* ```php
645+
* Yii::$app->db->createCommand()->createTable('post', [
646+
* 'id' => 'pk',
647+
* 'title' => 'string',
648+
* 'text' => 'text',
649+
* 'column_name double precision null default null',
650+
* ]);
651+
* ```
641652
*
642653
* @param string $table the name of the table to be created. The name will be properly quoted by the method.
643654
* @param array $columns the columns (name => definition) in the new table.

framework/db/Migration.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,24 @@ public function delete($table, $condition = '', $params = [])
305305
*
306306
* The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'),
307307
* where name stands for a column name which will be properly quoted by the method, and definition
308-
* stands for the column type which can contain an abstract DB type.
308+
* stands for the column type which must contain an abstract DB type.
309309
*
310310
* The [[QueryBuilder::getColumnType()]] method will be invoked to convert any abstract type into a physical one.
311311
*
312312
* If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
313313
* put into the generated SQL.
314+
*
315+
* Example usage:
316+
* ```php
317+
* class m200000_000000_create_table_fruits extends \yii\db\Migration
318+
* {
319+
* public function safeUp()
320+
* {
321+
* $this->createTable('{{%fruits}}', [
322+
* // ...
323+
* 'column_name double precision null default null',
324+
* ```
325+
314326
*
315327
* @param string $table the name of the table to be created. The name will be properly quoted by the method.
316328
* @param array $columns the columns (name => definition) in the new table.

framework/db/QueryBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ public function delete($table, $condition, &$params)
692692
*
693693
* The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'),
694694
* where name stands for a column name which will be properly quoted by the method, and definition
695-
* stands for the column type which can contain an abstract DB type.
695+
* stands for the column type which must contain an abstract DB type.
696696
* The [[getColumnType()]] method will be invoked to convert any abstract type into a physical one.
697697
*
698698
* If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
@@ -705,6 +705,7 @@ public function delete($table, $condition, &$params)
705705
* 'id' => 'pk',
706706
* 'name' => 'string',
707707
* 'age' => 'integer',
708+
* 'column_name double precision null default null', # definition only example
708709
* ]);
709710
* ```
710711
*

0 commit comments

Comments
 (0)