Skip to content
Snippets Groups Projects
Verified Commit 6337aa9d authored by Jiří Pudil's avatar Jiří Pudil
Browse files

add docs

parent 01c06b3c
No related branches found
No related tags found
1 merge request!58Make nullability explicit (not only) in ArrayType and CompositeType
Pipeline #59061 passed
......@@ -433,6 +433,12 @@ You can map values to an array via the `ArrayType`. This formats the items using
$dateArrayType = ArrayType::of(new DateType());
```
Note that while arrays in PostgreSQL can contain `NULL`, `ArrayType` rejects null values unless they are explicitly allowed:
```php
$nullableDateArrayType = ArrayType::of(NullableType::of(new DateType()));
```
##### Enum types
You can map native PHP enumerations to PostgreSQL's enums using the `EnumType`. This requires that the provided enum is a `\BackedEnum`, and serializes it to its backing value:
......@@ -481,3 +487,24 @@ $moneyType = new class extends CompositeType {
}
};
```
Similarly to arrays, in PostgreSQL, composite type fields are always nullable. However, `CompositeType` rejects null values except in positions where they are explicitly allowed:
```php
$nullableDateArrayType = ArrayType::of(NullableType::of(new DateType()));
```
```php
$moneyType = new class extends CompositeType {
public function __construct()
{
parent::__construct(
new Database\NamedType(new Database\Identifier('public', 'money')),
NullableType::of(DecimalType::decimal()),
new CurrencyType(),
);
}
// ...
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment