Completed
Push — 2.x ( 0b6590...78009d )
by Aleksei
20s queued 15s
created

Options::withIgnoreUninitializedRelations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM;
6
7
/**
8
 * ORM behavior options.
9
 */
10
final class Options
11
{
12
    /**
13
     * @readonly
14
     */
15
    public bool $ignoreUninitializedRelations = true;
16
17
    /**
18
     * If TRUE, ORM will ignore relations on uninitialized Entity properties.
19
     * In this case, `unset($entity->relation)` will not change the relation when saving,
20
     * and it will hydrate it if the relation is loaded in the query.
21
     *
22
     * If FALSE, uninitialized properties will be treated as NULL (an empty collection or empty value).
23
     * `unset($entity->relation)` will lead to a change in the relation
24
     * (removing the link with another entity or entities).
25
     */
26
    public function withIgnoreUninitializedRelations(bool $value): static
27
    {
28
        $clone = clone $this;
29
        $clone->ignoreUninitializedRelations = $value;
30
        return $clone;
31
    }
32
}
33