Answer the question
In order to leave comments, you need to log in
Symfony 4 - Doctrine - Repository how to pull the correct data type??
Hello Forum,
I have a problem with the data type,
here is the method from my repository:
public function getAllIds($objektId, $uid):array
{
$conn = $this->getEntityManager()->getConnection();
$sql = '
SELECT o.id as id, a.id as aid,l.id as lid FROM immo_miete o
LEFT JOIN immo_ausstattung a
ON o.id = a.fk_mid_id
LEFT JOIN immo_lage l
ON o.id=l.fk_mid_id
WHERE o.id = :objektId
AND o.uid_id=:uid
ORDER BY o.id ASC
';
$stmt = $conn->prepare($sql);
$stmt->execute(['objektId' => $objektId, 'uid' => $uid]);
return $stmt->fetch();
}
$ids = $this
->entityManager
->getRepository(Objekt::class)
->getAllIds(1, $this->uid);
echo gettype ($ids['id']);
Answer the question
In order to leave comments, you need to log in
by default, pdo receives numbers as strings, and this, if desired, is simply treated.
recipe for pdo - Is it possible to get a number when querying the database?
recipe specifically for doctrine - https://coderwall.com/p/goyc8w/how-to-stop-doctrin...
No way. Doctrine does not cast data types when executing a regular SQL query. Use array_map .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question