Skip to content

Commit bb735e6

Browse files
committed
clean up upgrade guide
1 parent b6f18fa commit bb735e6

1 file changed

Lines changed: 19 additions & 43 deletions

File tree

docs/upgrade.md

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
11
# 1.x -> 2.x
2-
2.x has a number of breaking API changes.
2+
2.x has a number of breaking API changes to be aware of. First, be aware that the minimum required PHP version is now 8.1. Other than that, there are some key API changes to be aware of.
33

4-
#### methods
4+
## Methods
55

6-
- [Model::find()](#modelfind)
7-
- [Model::all](#modelall)
8-
- [Model::count()](#modelcount)
9-
- [Model::delete_all()](#modeldelete_all)
10-
- [Model::update_all()](#modelupdate_all)
11-
- [Model::find_all_by_...()](#modelfind_all_by_attribute)
12-
- [Model::table()](#modeltable)
6+
### `Model::find`
137

14-
#### static properties
15-
16-
- [Model::$has_one](#modelhas_one)
17-
- [Model::$has_many](#modelhas_many)
18-
- [Model::$belongs_to](#modelbelongs_to)
19-
- [Model::$validates_inclusion_of](#modelvalidates_inclusion_of)
20-
21-
#### other changes
22-
- [Table::delete](#tabledelete)
23-
- [Table::update](#tableupdate)
24-
- [Config::set_model_directory](#configset_model_directory)
25-
- [exceptions location](#exceptions-location)
26-
27-
# Methods
28-
29-
## `Model::find`
308
Much of the old `find` functionality has been moved to `Relation`. Most notably, the `conditions` argument is no longer supported, and has been replaced by `where()`:
319
```php
3210
// 1.x
@@ -68,7 +46,7 @@ $book = Book::first();
6846
$book = Book::last();
6947
```
7048

71-
## `Model::all`
49+
### `Model::all`
7250
`Model::all()` no longer takes any arguments, and now returns an iterable `Relation` instead of an array of models:
7351
```php
7452
// 1.x
@@ -89,7 +67,7 @@ $books = Book::find('all', ['conditions'=>['title = ?', 'Walden']]);
8967
$books = Book::all()->where('title = ?', 'Walden')->to_a();
9068
```
9169

92-
## `Model::count`
70+
### `Model::count`
9371
The changes to `count` mirror the changes to `find`:
9472
```php
9573
// 1.x
@@ -99,7 +77,7 @@ $numBooks = Book::count(['conditions'=>['title = ?', 'Walden']]);
9977
$books = Book::where('title = ?', 'Walden')->count();
10078
```
10179

102-
## `Model::delete_all`
80+
### `Model::delete_all`
10381
Likewise for `delete_all`:
10482
```php
10583
// 1.x
@@ -109,7 +87,7 @@ $numDeleted = Book::delete_all(['conditions'=>['title = ?', 'Walden']]);
10987
$numDeleted = Book::where('title = ?', 'Walden')->delete_all();
11088
```
11189

112-
## `Model::update_all`
90+
### `Model::update_all`
11391
`update_all` has undergone a similar transformation, and now simply takes a string or hash of attributes as an argument:
11492
```php
11593
// 1.x
@@ -124,7 +102,7 @@ $numUpdated = Book::where(['title = ?', 'Walden'])->update_all([
124102
]);
125103
```
126104

127-
## `Model::find_all_by_<attribute>`
105+
### `Model::find_all_by_<attribute>`
128106
The `find_all_by...` style of magic method has been removed entirely.
129107
```php
130108
// 1.x
@@ -134,7 +112,7 @@ $books = Book::find_all_by_title('Ubik');
134112
$books = Book::where('title = ?', 'Ubik')->to_a();
135113
```
136114

137-
## `Model::table`
115+
### `Model::table`
138116
The static `table` accessor on `Model` is now protected. If you were making calls directly on `Table`, you will need to refactor your code.
139117
```php
140118
// 1.x
@@ -150,11 +128,11 @@ If you do need access to the table instance for some reason, you can still get t
150128
```
151129

152130

153-
# static properties
131+
## Static Properties
154132

155133
The static relationship properties have changed shape, moving from a flat array to a key-config format:
156134

157-
## `Model::$has_one`
135+
### `Model::$has_one`
158136

159137
```php
160138
// 1.x
@@ -183,7 +161,7 @@ class Author extends ActiveRecord
183161
}
184162
```
185163

186-
## `Model::$has_many`
164+
### `Model::$has_many`
187165

188166
```php
189167
// 1.x
@@ -209,7 +187,7 @@ class Person extends ActiveRecord
209187
}
210188
```
211189

212-
## `Model::$belongs_to`
190+
### `Model::$belongs_to`
213191

214192
```php
215193
// 1.x
@@ -234,7 +212,7 @@ class Person extends ActiveRecord
234212
}
235213
```
236214

237-
## `Model::$validates_inclusion_of`
215+
### `Model::$validates_inclusion_of`
238216

239217
(note: the same changes apply for `Model::$validates_exclusion_of`)
240218

@@ -257,9 +235,9 @@ class Book extends ActiveRecord
257235
}
258236
```
259237

260-
# other changes
238+
## Other Changes
261239

262-
## `Table::update`
240+
### `Table::update`
263241
You generally shouldn't be working directly with a `Table` instance, but if you are you should be aware that the `update` method has changed shape:
264242
```php
265243
// 1.x
@@ -274,7 +252,7 @@ $options = [
274252
$table->update([ 'title' => 'Walden' ], $options); // where $options is a RelationOptions.
275253
```
276254

277-
## `Table::delete`
255+
### `Table::delete`
278256
You generally shouldn't be working directly with a `Table` instance, but if you are you should be aware that the `delete` method has changed shape:
279257
```php
280258
// 1.x
@@ -289,7 +267,7 @@ $options = [
289267
$table->delete($options); // where $options is a RelationOptions.
290268
```
291269

292-
## `Config::set_model_directory`
270+
### `Config::set_model_directory`
293271

294272
`Config::set_model_directory` has been removed, meaning that the active record library no longer maintains its own autoloader or knowledge of where your models are kept. In 2.0 it is recommended to use your own autoloader to manage your models as you would any other classes in your project.
295273

@@ -321,9 +299,7 @@ class Author extends Model
321299

322300
```
323301

324-
# other changes
325-
326-
## exceptions location
302+
### exceptions location
327303

328304
All crafted exceptions have moved to a new home in the `Exceptions` namespace.
329305

0 commit comments

Comments
 (0)