0

I have 2 tables. One has 2 primary keys i.e. composite key. And same is foreign key in another table. Now Doctrine always return object for foreign key not value. In the case of single primary key I have somehow managed to get it but in case of composite I am not sure how to do it.

Code in case of single primary key as follows:

$patient = $this->entity->getPatient();
$patient_vars = $patient->toString(); // Inernal function to get private variables
$em = $this->doctrine->getManager();
$metaLabTest = $em->getClassMetadata(get_class($patient));
$identifierLabTest = $metaLabTest->getIdentifier($patient);
$metaPatient = $em->getClassMetadata(get_class($patient_vars[$identifierLabTest[0]]));
$identifierPatient = $metaPatient->getIdentifier();
$getFn = "get".$identifierPatient[0];
return $patient_vars[$identifierLabTest[0]]->$getFn();

Any suggestion for above will appreciated as well as I am pretty new to doctrine and symfony.

Thanks in advance.

user3170450
  • 375
  • 3
  • 20
  • Is there a particular reason why you want to work with the raw keys? – andy Oct 06 '14 at 12:31
  • I just want to return the simple value of foreign key but Doctrine return the object. So I just tried the above mentioned method and it worked but not in case of composite key. Please suggest if you have some better way to achieve this. – user3170450 Oct 07 '14 at 07:04
  • Is [this question](http://stackoverflow.com/questions/8211679/can-you-get-a-foreign-key-from-an-object-in-doctine2-without-loading-that-object) what you are looking for? I still don't get your question. The whole point of doctrine is to provide you with objects rather than raw database access. – andy Oct 07 '14 at 07:09
  • Yes my question is related to your mentioned question but it doesn't work if entity have composite key and that is my question. Please let me know if its clear or I will try to more elaborate it. – user3170450 Oct 07 '14 at 07:40
  • Without any structure of your entities and database, I don't know what you are trying to do here. – andy Oct 07 '14 at 08:07

1 Answers1

0

You should look into Hydration to control what Doctrine generates. what is doctrine hydration?

MECU
  • 770
  • 1
  • 11
  • 25