You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/reference/working-with-associations.rst
+32-3Lines changed: 32 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -736,6 +736,35 @@ methods:
736
736
737
737
.. note::
738
738
739
-
There is a limitation on the compatibility of Criteria comparisons.
740
-
You have to use scalar values only as the value in a comparison or
741
-
the behaviour between different backends is not the same.
739
+
Depending on whether the collection has already been loaded from the
740
+
database or not, criteria matching may happen at the database/SQL level
741
+
or on objects in memory. This may lead to different results and come
742
+
surprising, for example when a code change in one place leads to a collection
743
+
becoming initialized and, as a side effect, returning a different result
744
+
or even breaking a ``matching()`` call somewhere else. Also, collection
745
+
initialization state in practical use cases may differ from the one covered
746
+
in unit tests.
747
+
748
+
Database level comparisons are based on scalar representations of the values
749
+
stored in entity properties. The field names passed to expressions correspond
750
+
to property names. Comparison and sorting may be affected by
751
+
database-specific behavior. For example, MySQL enum types sort by index position,
752
+
not lexicographically by value.
753
+
754
+
In-memory handling is based on the ``Selectable`` API of `Doctrine Collections <https://www.doctrine-project.org/projects/doctrine-collections/en/stable/index.html#matching>`.
755
+
In this case, field names passed to expressions are being used to derive accessor
756
+
method names. Strict type comparisons are used for equal and not-equal checks,
757
+
and generally PHP language rules are being used for other comparison operators
758
+
or sorting.
759
+
760
+
As a general guidance, for consistent results use the Criteria API with scalar
761
+
values only. Note that ``DateTime`` and ``DateTimeImmutable`` are two predominant
762
+
examples of value objects that are *not* scalars.
763
+
764
+
Refrain from using special database-level column types or custom Doctrine Types
765
+
that may lead to database-specific comparison or sorting rules being applied, or
766
+
to database-level values being different from object field values.
767
+
768
+
Provide accessor methods for all entity fields used in criteria expressions,
769
+
and implement those methods in a way that their return value is the
0 commit comments