Skip to content

Commit ec57b0b

Browse files
authored
Fix UPGRADE.md (#20458)
1 parent 6ee5d95 commit ec57b0b

File tree

1 file changed

+105
-107
lines changed

1 file changed

+105
-107
lines changed

framework/UPGRADE.md

Lines changed: 105 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ if you want to upgrade from version A to version C and there is
5151
version B between A and C, you need to follow the instructions
5252
for both A and B.
5353

54-
Upgrade from Yii 2.0.53
54+
Upgrade from Yii 2.0.52
5555
-----------------------
5656

57-
* `ErrorHandler::convertExceptionToError()` has been deprecated and will be removed in version 22.0.
57+
* `ErrorHandler::convertExceptionToError()` has been deprecated and will be removed in version 2.2.0.
5858

5959
This method was deprecated due to `PHP 8.4` deprecating the use of `E_USER_ERROR` with `trigger_error()`.
6060
The framework now handles exceptions in `__toString()` methods more appropriately based on the PHP version.
@@ -86,8 +86,6 @@ Upgrade from Yii 2.0.53
8686
}
8787
```
8888

89-
Upgrade from Yii 2.0.52
90-
-----------------------
9189
* There was a bug when loading fixtures into PostgreSQL database, the table sequences were not reset. If you used a work-around or if you depended on this behavior, you are advised to review your code.
9290

9391
Upgrade from Yii 2.0.51
@@ -102,109 +100,109 @@ Upgrade from Yii 2.0.50
102100

103101
* Correcting the behavior for `JSON` column type in `MariaDb`.
104102

105-
Example usage of `JSON` column type in `db`:
106-
107-
```php
108-
<?php
109-
110-
use yii\db\Schema;
111-
112-
$db = Yii::$app->db;
113-
$command = $db->createCommand();
114-
115-
// Create a table with a JSON column
116-
$command->createTable(
117-
'products',
118-
[
119-
'id' => Schema::TYPE_PK,
120-
'details' => Schema::TYPE_JSON,
121-
],
122-
)->execute();
123-
124-
// Insert a new product
125-
$command->insert(
126-
'products',
127-
[
128-
'details' => [
129-
'name' => 'apple',
130-
'price' => 100,
131-
'color' => 'blue',
132-
'size' => 'small',
133-
],
134-
],
135-
)->execute();
136-
137-
// Read all products
138-
$records = $db->createCommand('SELECT * FROM products')->queryAll();
139-
```
140-
141-
Example usage of `JSON` column type in `ActiveRecord`:
142-
143-
```php
144-
<?php
145-
146-
namespace app\model;
147-
148-
use yii\db\ActiveRecord;
149-
150-
class ProductModel extends ActiveRecord
151-
{
152-
public static function tableName()
153-
{
154-
return 'products';
155-
}
156-
157-
public function rules()
158-
{
159-
return [
160-
[['details'], 'safe'],
161-
];
162-
}
163-
}
164-
```
165-
166-
```php
167-
<?php
168-
169-
use app\model\ProductModel;
170-
171-
// Create a new product
172-
$product = new ProductModel();
173-
174-
// Set the product details
175-
$product->details = [
176-
'name' => 'windows',
177-
'color' => 'red',
178-
'price' => 200,
179-
'size' => 'large',
180-
];
181-
182-
// Save the product
183-
$product->save();
184-
185-
// Read the first product
186-
$product = ProductModel::findOne(1);
187-
188-
// Get the product details
189-
$details = $product->details;
190-
191-
echo 'Name: ' . $details['name'];
192-
echo 'Color: ' . $details['color'];
193-
echo 'Size: ' . $details['size'];
194-
195-
// Read all products with color red
196-
$products = ProductModel::find()
197-
->where(new \yii\db\Expression('JSON_EXTRACT(details, "$.color") = :color', [':color' => 'red']))
198-
->all();
199-
200-
// Loop through all products
201-
foreach ($products as $product) {
202-
$details = $product->details;
203-
echo 'Name: ' . $details['name'];
204-
echo 'Color: ' . $details['color'];
205-
echo 'Size: ' . $details['size'];
206-
}
207-
```
103+
Example usage of `JSON` column type in `db`:
104+
105+
```php
106+
<?php
107+
108+
use yii\db\Schema;
109+
110+
$db = Yii::$app->db;
111+
$command = $db->createCommand();
112+
113+
// Create a table with a JSON column
114+
$command->createTable(
115+
'products',
116+
[
117+
'id' => Schema::TYPE_PK,
118+
'details' => Schema::TYPE_JSON,
119+
],
120+
)->execute();
121+
122+
// Insert a new product
123+
$command->insert(
124+
'products',
125+
[
126+
'details' => [
127+
'name' => 'apple',
128+
'price' => 100,
129+
'color' => 'blue',
130+
'size' => 'small',
131+
],
132+
],
133+
)->execute();
134+
135+
// Read all products
136+
$records = $db->createCommand('SELECT * FROM products')->queryAll();
137+
```
138+
139+
Example usage of `JSON` column type in `ActiveRecord`:
140+
141+
```php
142+
<?php
143+
144+
namespace app\model;
145+
146+
use yii\db\ActiveRecord;
147+
148+
class ProductModel extends ActiveRecord
149+
{
150+
public static function tableName()
151+
{
152+
return 'products';
153+
}
154+
155+
public function rules()
156+
{
157+
return [
158+
[['details'], 'safe'],
159+
];
160+
}
161+
}
162+
```
163+
164+
```php
165+
<?php
166+
167+
use app\model\ProductModel;
168+
169+
// Create a new product
170+
$product = new ProductModel();
171+
172+
// Set the product details
173+
$product->details = [
174+
'name' => 'windows',
175+
'color' => 'red',
176+
'price' => 200,
177+
'size' => 'large',
178+
];
179+
180+
// Save the product
181+
$product->save();
182+
183+
// Read the first product
184+
$product = ProductModel::findOne(1);
185+
186+
// Get the product details
187+
$details = $product->details;
188+
189+
echo 'Name: ' . $details['name'];
190+
echo 'Color: ' . $details['color'];
191+
echo 'Size: ' . $details['size'];
192+
193+
// Read all products with color red
194+
$products = ProductModel::find()
195+
->where(new \yii\db\Expression('JSON_EXTRACT(details, "$.color") = :color', [':color' => 'red']))
196+
->all();
197+
198+
// Loop through all products
199+
foreach ($products as $product) {
200+
$details = $product->details;
201+
echo 'Name: ' . $details['name'];
202+
echo 'Color: ' . $details['color'];
203+
echo 'Size: ' . $details['size'];
204+
}
205+
```
208206

209207
Upgrade from Yii 2.0.48
210208
-----------------------

0 commit comments

Comments
 (0)