Passed
Pull Request — 2.x (#528)
by Aleksei
17:59
created

Options::withGroupByToDeduplicate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
     * @note will be set to TRUE in the next major version.
15
     */
16
    public bool $ignoreUninitializedRelations = true;
17
18
    /**
19
     * @readonly
20
     * @note will be set to TRUE in the next major version.
21
     */
22
    public bool $groupByToDeduplicate = false;
23
24
    /**
25
     * If TRUE, ORM will ignore relations on uninitialized Entity properties.
26
     * In this case, `unset($entity->relation)` will not change the relation when saving,
27
     * and it will hydrate it if the relation is loaded in the query.
28
     *
29
     * If FALSE, uninitialized properties will be treated as NULL (an empty collection or empty value).
30
     * `unset($entity->relation)` will lead to a change in the relation
31
     * (removing the link with another entity or entities).
32
     */
33
    public function withIgnoreUninitializedRelations(bool $value): static
34
    {
35
        $clone = clone $this;
36
        $clone->ignoreUninitializedRelations = $value;
37
        return $clone;
38
    }
39
40
    /**
41
     * If TRUE, ORM will use GROUP BY to deduplicate entities in Select queries in cases where
42
     * `limit` and `offset` with JOINs are used.
43
     *
44
     * If FALSE, ORM will not use GROUP BY, which may lead wrong results in cases where
45
     * `limit` and `offset` are used with JOINs.
46
     */
47
    public function withGroupByToDeduplicate(bool $value): static
48
    {
49
        $clone = clone $this;
50
        $clone->groupByToDeduplicate = $value;
51
        return $clone;
52
    }
53
}
54