Answer the question
In order to leave comments, you need to log in
How to select all fields of a table using DQL in HYDRATE_ARRAY mode?
There is an Entity Treatment whose property names are different from the names of the table columns in the database.
In a select query, all fields are selected, except for the "contract" field, which is a foreign key to the dictionary.
Here it is:
/**
* @var \Medcard\Entity\Contract
*
* @ORM\ManyToOne(targetEntity="Medcard\Entity\Contract")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="contract_id", referencedColumnName="id")
* })
*/
private $contract;
$data = $this->entityManager->createQuery('SELECT e FROM ' . self::ENTITY_NAME
. ' e WHERE e.medcard = ?1')
->setParameter(1, $id)->getSingleResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
$data = $this->entityManager->createQuery('SELECT e, c.id as contract FROM '
. self::ENTITY_NAME . ' e ' . ' JOIN e.contract c WHERE e.medcard = ?1')
->setParameter(1, $id)->getSingleResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
Answer the question
In order to leave comments, you need to log in
doctrine-orm.readthedocs.org/en/latest/reference/d...
try this:IDENTITY(e.contract) as contract
I just need to get all the data from the table, but with field names that correspond to properties in the Entity, and not the DB, so that later hydration can be performed. (i.e. not contract_id, but contract, medcard_id -> medcard)
To do this, in Entity, simply specify the field name that you need, and for database fields, redefine it
. For example:/** * @var string * @ORM\Column(type="string",name="last_name") */ protected $lastName;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question