diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 431b237a6..e9d214311 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -468,7 +468,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister } } else if ($this->_class->name != $this->_class->rootEntityName || ! $this->_class->isIdGeneratorIdentity() || $this->_class->identifier[0] != $name) { - $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class, $this->_platform); + $columns[] = $this->quoteStrategy->getColumnName($name, $this->_class, $this->_platform); + $this->_columnTypes[$name] = $this->_class->fieldMappings[$name]['type']; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php new file mode 100755 index 000000000..eca15cea3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php @@ -0,0 +1,177 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2012Item'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2012ItemPerson'), + )); + } + + public function testIssue() + { + $item = new DDC2012ItemPerson(); + $item->tsv = array('word1', 'word2', 'word3'); + + $this->_em->persist($item); + $this->_em->flush(); + $this->_em->clear(); + + $item = $this->_em->find(get_class($item), $item->id); + + $this->assertArrayHasKey('convertToDatabaseValueSQL', DDC2012TsVectorType::$calls); + $this->assertArrayHasKey('convertToDatabaseValue', DDC2012TsVectorType::$calls); + $this->assertArrayHasKey('convertToPHPValue', DDC2012TsVectorType::$calls); + + $this->assertCount(1, DDC2012TsVectorType::$calls['convertToDatabaseValueSQL']); + $this->assertCount(1, DDC2012TsVectorType::$calls['convertToDatabaseValue']); + $this->assertCount(1, DDC2012TsVectorType::$calls['convertToPHPValue']); + + $this->assertInstanceOf(__NAMESPACE__ . '\DDC2012Item', $item); + $this->assertEquals(array('word1', 'word2', 'word3'), $item->tsv); + + + $item->tsv = array('word1', 'word2'); + + $this->_em->persist($item); + $this->_em->flush(); + $this->_em->clear(); + + $item = $this->_em->find(get_class($item), $item->id); + + $this->assertCount(2, DDC2012TsVectorType::$calls['convertToDatabaseValueSQL']); + $this->assertCount(2, DDC2012TsVectorType::$calls['convertToDatabaseValue']); + $this->assertCount(2, DDC2012TsVectorType::$calls['convertToPHPValue']); + + $this->assertInstanceOf(__NAMESPACE__ . '\DDC2012Item', $item); + $this->assertEquals(array('word1', 'word2'), $item->tsv); + } +} + +/** + * @Table(name="ddc2010_item") + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="type_id", type="smallint") + * @DiscriminatorMap({ + * 1 = "DDC2012ItemPerson" + * }) + */ +class DDC2012Item +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + public $id; + + /** + * @Column(name="tsv", type="tsvector", nullable=true) + */ + public $tsv; +} + +/** + * @Table(name="ddc2010_item_person") + * @Entity + */ +class DDC2012ItemPerson extends DDC2012Item +{ + +} + +class DDC2012TsVectorType extends Type +{ + const MYTYPE = 'tsvector'; + + public static $calls = array(); + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (is_array($value)) { + $value = implode(" ", $value); + } + + self::$calls[__FUNCTION__][] = array( + 'value' => $value, + 'platform' => $platform, + ); + + return $value; + } + + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + self::$calls[__FUNCTION__][] = array( + 'value' => $value, + 'platform' => $platform, + ); + + return explode(" ", strtolower($value)); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) + { + self::$calls[__FUNCTION__][] = array( + 'sqlExpr' => $sqlExpr, + 'platform' => $platform, + ); + + // changed to upper expression to keep the test compatible with other Databases + //sprintf('to_tsvector(%s)', $sqlExpr); + + return $platform->getUpperExpression($sqlExpr); + } + + /** + * {@inheritdoc} + */ + public function canRequireSQLConversion() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::MYTYPE; + } +} \ No newline at end of file