@@ -411,6 +411,37 @@ private function _fetchManyToOne(&$entity, $property)
411
411
}, $ results );
412
412
}
413
413
414
+ /**
415
+ * @param IEntity $entity
416
+ * @param string $property
417
+ * @throws \ElementaryFramework\Annotations\Exceptions\AnnotationException
418
+ * @throws \ElementaryFramework\LightQL\Exceptions\LightQLException
419
+ */
420
+ private function _fetchOneToOne (&$ entity , $ property )
421
+ {
422
+ $ oneToOne = Annotations::ofProperty ($ entity , $ property , "@oneToOne " );
423
+ $ referencedEntityAnnotations = Annotations::ofClass ($ oneToOne [0 ]->entity , "@entity " );
424
+ $ mappedPropertyAnnotation = Annotations::ofProperty ($ oneToOne [0 ]->entity , $ this ->_getReferencePropertyName ($ this ->getEntityClassName ()), "@oneToOne " );
425
+
426
+ $ lightql = $ this ->entityManager ->getLightQL ();
427
+
428
+ $ result = $ lightql
429
+ ->from ($ referencedEntityAnnotations [0 ]->table )
430
+ ->where (array ("{$ referencedEntityAnnotations [0 ]->table }. {$ oneToOne [0 ]->referencedColumn }" => $ lightql ->quote ($ entity ->get ($ mappedPropertyAnnotation [0 ]->referencedColumn ))))
431
+ ->selectFirst ("{$ referencedEntityAnnotations [0 ]->table }.* " );
432
+
433
+ $ propertyName = $ this ->_getReferencePropertyName ($ oneToOne [0 ]->entity );
434
+ $ className = $ oneToOne [0 ]->entity ;
435
+
436
+ $ entity ->$ propertyName = $ result ;
437
+
438
+ if ($ result !== null ) {
439
+ $ entity ->$ propertyName = new $ className ($ result );
440
+ $ referencedPropertyName = $ this ->_getReferencePropertyName ($ this ->getEntityClassName ());
441
+ $ entity ->{$ propertyName }->{$ referencedPropertyName } = $ entity ;
442
+ }
443
+ }
444
+
414
445
/**
415
446
* @param $rawEntities
416
447
* @param $annotations
@@ -437,6 +468,8 @@ private function _parseRawEntities($rawEntities, $annotations): array
437
468
$ this ->_fetchOneToMany ($ entity , $ property ->name );
438
469
} elseif (Annotations::propertyHasAnnotation ($ entity , $ property ->name , "@manyToOne " )) {
439
470
$ this ->_fetchManyToOne ($ entity , $ property ->name );
471
+ } elseif (Annotations::propertyHasAnnotation ($ entity , $ property ->name , "@oneToOne " )) {
472
+ $ this ->_fetchOneToOne ($ entity , $ property ->name );
440
473
}
441
474
}
442
475
}
0 commit comments