mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 14:28:27 +08:00
added example to db migration query builder usage
This commit is contained in:
@ -704,8 +704,17 @@ Below is the list of all these database accessing methods:
|
|||||||
* [[yii\db\Migration::dropCommentFromTable()|dropCommentFromTable()]]: dropping comment from table
|
* [[yii\db\Migration::dropCommentFromTable()|dropCommentFromTable()]]: dropping comment from table
|
||||||
|
|
||||||
> Info: [[yii\db\Migration]] does not provide a database query method. This is because you normally do not need
|
> Info: [[yii\db\Migration]] does not provide a database query method. This is because you normally do not need
|
||||||
to display extra message about retrieving data from a database. It is also because you can use the powerful
|
> to display extra message about retrieving data from a database. It is also because you can use the powerful
|
||||||
[Query Builder](db-query-builder.md) to build and run complex queries.
|
> [Query Builder](db-query-builder.md) to build and run complex queries.
|
||||||
|
> Using Query Builder in a migration may look like this:
|
||||||
|
>
|
||||||
|
> ```php
|
||||||
|
> // update status field for all users
|
||||||
|
> foreach((new Query)->from('users')->each() as $user) {
|
||||||
|
> $this->update('users', ['status' => 1], ['id' => $user['id']);
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
|
|
||||||
> Note: When manipulating data using a migration you may find that using your [Active Record](db-active-record.md) classes
|
> Note: When manipulating data using a migration you may find that using your [Active Record](db-active-record.md) classes
|
||||||
> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast
|
> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast
|
||||||
|
Reference in New Issue
Block a user