Skip to content

Commit 4e98189

Browse files
committed
DOC Document fixed DBField options array
1 parent 522e908 commit 4e98189

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

en/02_Developer_Guides/00_Model/04_Data_Types_and_Casting.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ to be applied to all existing and new records when the column is added in the da
8181
for the first time. You do this by passing an argument for the default value in your
8282
`$db` items.
8383

84-
For integer values, the default is the first parameter in the field specification.
84+
For integer and floating point values, the default is the first parameter in the field specification.
8585
For string values, you will need to declare this default using the options array.
8686
For enum values, it's the second parameter.
8787

88+
> [!WARNING]
89+
> MySQL doesn't support default values for `TEXT` columns, so you should not try to set a default value using the options array for `Text` or `HTMLText` fields when using MySQL.
90+
8891
For example:
8992

9093
```php
@@ -98,7 +101,8 @@ class Car extends DataObject
98101
private static $db = [
99102
'Wheels' => 'Int(4)',
100103
'Condition' => 'Enum("New,Fair,Junk", "Fair")',
101-
'Make' => 'Varchar(["default" => "Honda"])',
104+
// For Varchar, the size must be passed before the options array.
105+
'Make' => 'Varchar(255, ["default" => "Honda"])',
102106
];
103107
}
104108
```

en/08_Changelogs/6.2.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,9 @@ It's best practice to avoid using deprecated code where possible, but sometimes
119119
## Bug fixes
120120

121121
This release includes a number of bug fixes to improve a broad range of areas. Check the change logs for full details of these fixes split by module. Thank you to the community members that helped contribute these fixes as part of the release!
122+
123+
### `DBField` options array
124+
125+
Some [`DBField`](api:SilverStripe\ORM\FieldType\DBField) implementations take an array of options in the constructor. This is notably used to set default values for [`DBString`](api:SilverStripe\ORM\FieldType\DBString) subclasses as documented in the [default values documentation](/developer_guides/model/data_types_and_casting/#default-values) but can be used for other purposes as well.
126+
127+
When creating columns in the database, the options array wasn't being correctly passed through to the constructor, which made setting default values for string columns impossible among other things. This has been fixed.

0 commit comments

Comments
 (0)