Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Security Level: All
-
Labels:None
Description
When using a mapping Type that declares convertToDatabaseValue, the method is not always called in queries.
Example:
SELECT ... WHERE entity.field = ?1
(with entity.field being of custom type 'the_mapping_type')
Type::convertToDatabaseValue() is correctly called when using:
$query->setParameter('1', 'foo', 'the_mapping_type');
But it is not called when using:
$query->setParameter('1', 'foo');
which gives a query that returns invalid results.
Like other mapping types in this situation, there is no reason the type is not inferred automatically from the field.
I have written a failing test case in Doctrine\Tests\ORM\Functional\TypeValueSqlTest:
public function testQueryParameterWithoutType()
{
$entity = new CustomTypeUpperCase();
$entity->lowerCaseString = 'foo';
$this->_em->persist($entity);
$this->_em->flush();
$id = $entity->id;
$this->_em->clear();
$query = $this->_em->createQuery('SELECT c.id from Doctrine\Tests\Models\CustomType\CustomTypeUpperCase c where c.lowerCaseString = ?1');
$query->setParameter('1', 'foo');
$result = $query->getResult();
$this->assertCount(1, $result);
$this->assertEquals($id, $result[0]['id']);
}
Activity
Matthieu Napoli
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
When using a mapping Type that declares {{convertToDatabaseValue}}, the method is not always called in queries.
Example: {code} SELECT ... WHERE entity.field = ?1 {code} (with {{entity.field}} being of custom type 'the_mapping_type') {{convertToDatabaseValue}} is called when using: {code} $query->setParameter('1', 'foo', 'the_mapping_type'); {code} But it is not called when using: {code} $query->setParameter('1', 'foo'); {code} Like other mapping types in this situation, there is no reason the type is not inferred automatically from the field. I have written a failing test case in Doctrine\Tests\ORM\Functional\TypeValueSqlTest: {code} public function testQueryParameterWithoutType() { $entity = new CustomTypeUpperCase(); $entity->lowerCaseString = 'foo'; $this->_em->persist($entity); $this->_em->flush(); $id = $entity->id; $this->_em->clear(); $query = $this->_em->createQuery('SELECT c.id from Doctrine\Tests\Models\CustomType\CustomTypeUpperCase c where c.lowerCaseString = ?1'); $query->setParameter('1', 'foo'); $result = $query->getResult(); $this->assertCount(1, $result); $this->assertEquals($id, $result[0]['id']); } {code} |
When using a mapping Type that declares {{convertToDatabaseValue}}, the method is not always called in queries.
Example: {code} SELECT ... WHERE entity.field = ?1 {code} (with {{entity.field}} being of custom type 'the_mapping_type') {{Type::convertToDatabaseValue()}} is correctly called when using: {code} $query->setParameter('1', 'foo', 'the_mapping_type'); {code} But it is not called when using: {code} $query->setParameter('1', 'foo'); {code} which gives a query that returns invalid results. Like other mapping types in this situation, there is no reason the type is not inferred automatically from the field. I have written a failing test case in Doctrine\Tests\ORM\Functional\TypeValueSqlTest: {code} public function testQueryParameterWithoutType() { $entity = new CustomTypeUpperCase(); $entity->lowerCaseString = 'foo'; $this->_em->persist($entity); $this->_em->flush(); $id = $entity->id; $this->_em->clear(); $query = $this->_em->createQuery('SELECT c.id from Doctrine\Tests\Models\CustomType\CustomTypeUpperCase c where c.lowerCaseString = ?1'); $query->setParameter('1', 'foo'); $result = $query->getResult(); $this->assertCount(1, $result); $this->assertEquals($id, $result[0]['id']); } {code} |
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2290, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
See also http://www.doctrine-project.org/jira/browse/DDC-2224