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
Support for nesting attributes with PHP 8.1 (#9241)
* [GH-9240] Refactor Association/AttributeOverrides to use @NamedConstructorArguments with AnnotationDriver.
* [GH-9240] Add support for PHP 8.1 nested attributes.
Supported/new attributes are #[AttributeOverrides], #[AssociationOverrides], #[JoinTable] with nested joinColumns, inverseJoinColumns.
* [GH-9240] Add support for nesting Index, UniqueCosntraint into #[Table] on PHP 8.1
* Apply review comments by gregooire.
* Add documentation for new attributes.
* Add docs for new nested #[JoinTable] support of join columns
* Add docs for new nested #[Table] support of index, uniqueConstraints
* Rename "Required/Optional atttributes" to "Required/Optional parameters"
* Remove nesting for JoinTable#joinColumns and Table#indexes/uniqueConstraints again.
* Hosuekeeping: phpcs/psalm
* housekeeping
* Remove unused function imports.
In an inheritance hierarchy this attribute allows to override the
108
+
field mapping definitions of the parent mappings. It needs to be nested
109
+
within a ``#[AttributeOverrides]`` on the class level.
110
+
111
+
Required parameters:
112
+
113
+
- **name**: Name of the association mapping to overwrite.
114
+
- **column**: A nested ``#[Column]`` attribute with the overwritten field settings.
115
+
116
+
Examples:
117
+
118
+
.. code-block:: php
119
+
120
+
<?php
121
+
use Doctrine\ORM\Mapping\AttributeOverride;
122
+
use Doctrine\ORM\Mapping\AttributeOverrides;
123
+
use Doctrine\ORM\Mapping\Column;
124
+
use Doctrine\ORM\Mapping\Entity;
125
+
126
+
#[Entity]
127
+
#[AttributeOverrides([
128
+
new AttributeOverride(
129
+
name: "id",
130
+
column: new Column(name: "guest_id", type: "integer", length: 140)
131
+
),
132
+
new AttributeOverride(
133
+
name: "name",
134
+
column: new Column(name: "guest_name", nullable: false, unique: true, length: 240)
135
+
)]
136
+
)]
137
+
class DDC964Guest extends DDC964User
138
+
{
139
+
}
140
+
52
141
.. _attrref_column:
53
142
54
143
#[Column]
@@ -59,12 +148,12 @@ inside the instance variables PHP DocBlock comment. Any value hold
59
148
inside this variable will be saved to and loaded from the database
60
149
as part of the lifecycle of the instance variables entity-class.
61
150
62
-
Required attributes:
151
+
Required parameters:
63
152
64
153
- **type**: Name of the DBAL Type which does the conversion between PHP
65
154
and Database representation.
66
155
67
-
Optional attributes:
156
+
Optional parameters:
68
157
69
158
- **name**: By default the property name is used for the database
70
159
column name also, however the ``name`` attribute allows you to
@@ -165,7 +254,7 @@ Examples:
165
254
~~~~~~~~
166
255
Add caching strategy to a root entity or a collection.
167
256
168
-
Optional attributes:
257
+
Optional parameters:
169
258
170
259
- **usage**: One of ``READ_ONLY``, ``READ_WRITE`` or ``NONSTRICT_READ_WRITE``, By default this is ``READ_ONLY``.
171
260
- **region**: An specific region name
@@ -210,7 +299,7 @@ Example:
210
299
211
300
This attribute allows you to specify a user-provided class to generate identifiers. This attribute only works when both :ref:`#[Id] <attrref_id>` and :ref:`#[GeneratedValue(strategy: "CUSTOM")] <attrref_generatedvalue>` are specified.
212
301
213
-
Required attributes:
302
+
Required parameters:
214
303
215
304
- **class**: name of the class which should extend Doctrine\ORM\Id\AbstractIdGenerator
216
305
@@ -244,13 +333,13 @@ actually instantiated as.
244
333
If this attribute is not specified, the discriminator column defaults
245
334
to a string column of length 255 called ``dtype``.
246
335
247
-
Required attributes:
336
+
Required parameters:
248
337
249
338
250
339
- **name**: The column name of the discriminator. This name is also
251
340
used during Array hydration as key to specify the class-name.
252
341
253
-
Optional attributes:
342
+
Optional parameters:
254
343
255
344
256
345
- **type**: By default this is string.
@@ -319,7 +408,7 @@ attribute to establish the relationship between the two classes.
319
408
The embedded attribute is required on an entity's member variable,
320
409
in order to specify that it is an embedded class.
321
410
322
-
Required attributes:
411
+
Required parameters:
323
412
324
413
- **class**: The embeddable class
325
414
@@ -331,7 +420,7 @@ Required attributes:
331
420
Required attribute to mark a PHP class as an entity. Doctrine manages
332
421
the persistence of all classes marked as entities.
333
422
334
-
Optional attributes:
423
+
Optional parameters:
335
424
336
425
- **repositoryClass**: Specifies the FQCN of a subclass of the
337
426
``EntityRepository``. Use of repositories for entities is encouraged to keep
@@ -368,7 +457,7 @@ conjunction with #[Id].
368
457
If this attribute is not specified with ``#[Id]`` the ``NONE`` strategy is
369
458
used as default.
370
459
371
-
Optional attributes:
460
+
Optional parameters:
372
461
373
462
- **strategy**: Set the name of the identifier generation strategy.
374
463
Valid values are ``AUTO``, ``SEQUENCE``, ``IDENTITY``, ``UUID``
@@ -424,14 +513,14 @@ Attribute is used on the entity-class level. It provides a hint to the SchemaToo
424
513
generate a database index on the specified table columns. It only
425
514
has meaning in the ``SchemaTool`` schema generation context.
426
515
427
-
Required attributes:
516
+
Required parameters:
428
517
429
518
- **name**: Name of the Index
430
519
- **fields**: Array of fields. Exactly one of **fields, columns** is required.
431
520
- **columns**: Array of columns. Exactly one of **fields, columns** is required.
432
521
433
522
434
-
Optional attributes:
523
+
Optional parameters:
435
524
436
525
- **options**: Array of platform specific options:
437
526
@@ -546,9 +635,10 @@ are missing they will be computed considering the field's name and the current
546
635
547
636
The ``#[InverseJoinColumn]`` is the same as ``#[JoinColumn]`` and is used in the context
548
637
of a ``#[ManyToMany]`` attribute declaration to specifiy the details of the join table's
549
-
column information used for the join to the inverse entity.
638
+
column information used for the join to the inverse entity. This is only required
639
+
on PHP 8.0, where nested attributes are not yet supported.
550
640
551
-
Optional attributes:
641
+
Optional parameters:
552
642
553
643
- **name**: Column name that holds the foreign key identifier for
554
644
this relation. In the context of ``#[JoinTable]`` it specifies the column
@@ -596,7 +686,7 @@ details of the database join table. If you do not specify
596
686
using the affected table and the column names.
597
687
598
688
A notable difference to the annotation metadata support, ``#[JoinColumn]``
599
-
and ``#[InverseJoinColumn]`` are specified at the property level and are not
689
+
and ``#[InverseJoinColumn]`` can be specified at the property level and are not
600
690
nested within the ``#[JoinTable]`` attribute.
601
691
602
692
Required attribute:
@@ -623,14 +713,14 @@ Example:
623
713
Defines that the annotated instance variable holds a reference that
624
714
describes a many-to-one relationship between two entities.
625
715
626
-
Required attributes:
716
+
Required parameters:
627
717
628
718
629
719
- **targetEntity**: FQCN of the referenced target entity. Can be the
630
720
unqualified class name if both classes are in the same namespace.
631
721
*IMPORTANT:* No leading backslash!
632
722
633
-
Optional attributes:
723
+
Optional parameters:
634
724
635
725
636
726
- **cascade**: Cascade Option
@@ -659,14 +749,14 @@ additional, optional attribute that has reasonable default
659
749
configuration values using the table and names of the two related
660
750
entities.
661
751
662
-
Required attributes:
752
+
Required parameters:
663
753
664
754
665
755
- **targetEntity**: FQCN of the referenced target entity. Can be the
666
756
unqualified class name if both classes are in the same namespace.
667
757
*IMPORTANT:* No leading backslash!
668
758
669
-
Optional attributes:
759
+
Optional parameters:
670
760
671
761
672
762
- **mappedBy**: This option specifies the property name on the
@@ -720,7 +810,7 @@ The ``#[MappedSuperclass]`` attribute cannot be used in conjunction with
720
810
``#[Entity]``. See the Inheritance Mapping section for
721
811
:doc:`more details on the restrictions of mapped superclasses <inheritance-mapping>`.
722
812
723
-
Optional attributes:
813
+
Optional parameters:
724
814
725
815
- **repositoryClass**: Specifies the FQCN of a subclass of the EntityRepository.
726
816
That will be inherited for all subclasses of that Mapped Superclass.
@@ -756,13 +846,13 @@ be specified. When no
756
846
:ref:`#[JoinColumn] <attrref_joincolumn>` is specified it defaults to using the target entity table and
757
847
primary key column names and the current naming strategy to determine a name for the join column.
758
848
759
-
Required attributes:
849
+
Required parameters:
760
850
761
851
- **targetEntity**: FQCN of the referenced target entity. Can be the
762
852
unqualified class name if both classes are in the same namespace.
763
853
*IMPORTANT:* No leading backslash!
764
854
765
-
Optional attributes:
855
+
Optional parameters:
766
856
767
857
- **cascade**: Cascade Option
768
858
- **fetch**: One of LAZY or EAGER
@@ -786,13 +876,13 @@ Example:
786
876
#[OneToMany]
787
877
~~~~~~~~~~~~
788
878
789
-
Required attributes:
879
+
Required parameters:
790
880
791
881
- **targetEntity**: FQCN of the referenced target entity. Can be the
792
882
unqualified class name if both classes are in the same namespace.
793
883
*IMPORTANT:* No leading backslash!
794
884
795
-
Optional attributes:
885
+
Optional parameters:
796
886
797
887
- **cascade**: Cascade Option
798
888
- **orphanRemoval**: Boolean that specifies if orphans, inverse
@@ -916,11 +1006,11 @@ For use with ``#[GeneratedValue(strategy: "SEQUENCE")]`` this
916
1006
attribute allows to specify details about the sequence, such as
917
1007
the increment size and initial values of the sequence.
918
1008
919
-
Required attributes:
1009
+
Required parameters:
920
1010
921
1011
- **sequenceName**: Name of the sequence
922
1012
923
-
Optional attributes:
1013
+
Optional parameters:
924
1014
925
1015
- **allocationSize**: Increment the sequence by the allocation size
926
1016
when its fetched. A value larger than 1 allows optimization for
@@ -954,11 +1044,11 @@ placed on the entity-class level and is optional. If it is
954
1044
not specified the table name will default to the entity's
955
1045
unqualified classname.
956
1046
957
-
Required attributes:
1047
+
Required parameters:
958
1048
959
1049
- **name**: Name of the table
960
1050
961
-
Optional attributes:
1051
+
Optional parameters:
962
1052
963
1053
- **schema**: Name of the schema the table lies in.
964
1054
@@ -985,12 +1075,12 @@ generate a database unique constraint on the specified table
985
1075
columns. It only has meaning in the SchemaTool schema generation
986
1076
context.
987
1077
988
-
Required attributes:
1078
+
Required parameters:
989
1079
990
1080
- **name**: Name of the Index
991
1081
- **columns**: Array of columns.
992
1082
993
-
Optional attributes:
1083
+
Optional parameters:
994
1084
995
1085
- **options**: Array of platform specific options:
0 commit comments