summaryrefslogtreecommitdiffstats
path: root/vendor/doctrine/collections/docs/en/expressions.rst
blob: db943b246b34e7753742001648ccc45cca290117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Expressions
===========

The ``Doctrine\Common\Collections\Expr\Comparison`` class
can be used to create expressions to be used with the
``Doctrine\Common\Collections\Criteria`` class. It has the
following operator constants:

- ``Comparison::EQ``
- ``Comparison::NEQ``
- ``Comparison::LT``
- ``Comparison::LTE``
- ``Comparison::GT``
- ``Comparison::GTE``
- ``Comparison::IS``
- ``Comparison::IN``
- ``Comparison::NIN``
- ``Comparison::CONTAINS``
- ``Comparison::MEMBER_OF``
- ``Comparison::STARTS_WITH``
- ``Comparison::ENDS_WITH``

The ``Doctrine\Common\Collections\Criteria`` class has the following
API to be used with expressions:

where
-----

Sets the where expression to evaluate when this Criteria is searched for.

.. code-block:: php
    $expr = new Comparison('key', Comparison::EQ, 'value');

    $criteria->where($expr);

andWhere
--------

Appends the where expression to evaluate when this Criteria is searched for
using an AND with previous expression.

.. code-block:: php
    $expr = new Comparison('key', Comparison::EQ, 'value');

    $criteria->andWhere($expr);

orWhere
-------

Appends the where expression to evaluate when this Criteria is searched for
using an OR with previous expression.

.. code-block:: php
    $expr1 = new Comparison('key', Comparison::EQ, 'value1');
    $expr2 = new Comparison('key', Comparison::EQ, 'value2');

    $criteria->where($expr1);
    $criteria->orWhere($expr2);

orderBy
-------

Sets the ordering of the result of this Criteria.

.. code-block:: php
    $criteria->orderBy(['name' => Criteria::ASC]);

setFirstResult
--------------

Set the number of first result that this Criteria should return.

.. code-block:: php
    $criteria->setFirstResult(0);

getFirstResult
--------------

Gets the current first result option of this Criteria.

.. code-block:: php
    $criteria->setFirstResult(10);

    echo $criteria->getFirstResult(); // 10

setMaxResults
-------------

Sets the max results that this Criteria should return.

.. code-block:: php
    $criteria->setMaxResults(20);

getMaxResults
-------------

Gets the current max results option of this Criteria.

.. code-block:: php
    $criteria->setMaxResults(20);

    echo $criteria->getMaxResults(); // 20