99use Cycle \Annotated \Annotation \Entity ;
1010use Cycle \Annotated \Annotation \ForeignKey ;
1111use Cycle \Annotated \Annotation \GeneratedValue ;
12+ use Cycle \Annotated \Annotation \Obsolete ;
1213use Cycle \Annotated \Annotation \Relation as RelationAnnotation ;
1314use Cycle \Annotated \Exception \AnnotationException ;
1415use Cycle \Annotated \Exception \AnnotationRequiredArgumentsException ;
@@ -96,7 +97,7 @@ public function initEmbedding(Embeddable $emb, \ReflectionClass $class): EntityS
9697
9798 public function initFields (EntitySchema $ entity , \ReflectionClass $ class , string $ columnPrefix = '' ): void
9899 {
99- foreach ($ class -> getProperties ( ) as $ property ) {
100+ foreach ($ this -> getActualProperties ( $ class ) as $ property ) {
100101 try {
101102 $ column = $ this ->reader ->firstPropertyMetadata ($ property , Column::class);
102103 } catch (\Exception $ e ) {
@@ -119,7 +120,7 @@ public function initFields(EntitySchema $entity, \ReflectionClass $class, string
119120
120121 public function initRelations (EntitySchema $ entity , \ReflectionClass $ class ): void
121122 {
122- foreach ($ class -> getProperties ( ) as $ property ) {
123+ foreach ($ this -> getActualProperties ( $ class ) as $ property ) {
123124 $ metadata = $ this ->getPropertyMetadata ($ property , RelationAnnotation \RelationInterface::class);
124125
125126 foreach ($ metadata as $ meta ) {
@@ -413,4 +414,22 @@ private function isOnInsertGeneratedField(Field $field): bool
413414 default => $ field ->isPrimary (),
414415 };
415416 }
417+
418+ /**
419+ * @return \Generator<\ReflectionProperty>
420+ */
421+ private function getActualProperties (\ReflectionClass $ class ): \Generator
422+ {
423+ foreach ($ class ->getProperties () as $ property ) {
424+ // Obsolete property must not be included in the scheme.
425+ $ metadata = \iterator_to_array (
426+ $ this ->getPropertyMetadata ($ property , Obsolete::class),
427+ );
428+ if ([] !== $ metadata ) {
429+ continue ;
430+ }
431+
432+ yield $ property ;
433+ }
434+ }
416435}
0 commit comments