[DDC-2012] Inserting a new entity with a custom mapping type does not call convertToDatabaseValueSQL() when using InheritanceType("JOINED") Created: 04/Sep/12 Updated: 03/Oct/12 Resolved: 03/Oct/12 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | Mapping Drivers |
| Affects Version/s: | 2.2.3 |
| Fix Version/s: | 2.2.4, 2.3.1 |
| Security Level: | All |
| Type: | Bug | Priority: | Critical |
| Reporter: | Kaspars Sproģis | Assignee: | Fabio B. Silva |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
PHP |
||
| Attachments: |
|
| Description |
|
When using class type inheritance - @InheritanceType("JOINED") and inserting new entity with a custom mapping type, custom type method convertToDatabaseValueSQL() is never called. Here is sample class mapping: Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml /** * @Table(name="item") * @Entity * @InheritanceType("JOINED") * @DiscriminatorColumn(name="type_id", type="smallint") * @DiscriminatorMap({1 = "ItemPerson"}) */ class Item { /** * @Column(name="tsv", type="tsvector", nullable=true) */ protected $tsv; } /** * @Table(name="item_person") * @Entity */ class ItemPerson extends Item { } I am using the same custom TsvectorType with simple entities and even Mapped Superclasses and it works perfectly, however on InheritanceType("JOINED") method convertToDatabaseValueSQL() is never called :/ |
| Comments |
| Comment by Fabio B. Silva [ 24/Sep/12 ] |
|
Hi Kaspars, I can't reproduce, Thanks |
| Comment by Kaspars Sproģis [ 26/Sep/12 ] |
|
@Fabio thanks for looking into my problem It was quite strange, all i did was changed column that uses custom type to array and some minimal convertToDatabaseValue and convertToDatabaseValueSQL logic and convertToDatabaseValueSQL was never called. One more thing i noticed, this bug only appears on persist and not on merge. Thanks |
| Comment by Fabio B. Silva [ 29/Sep/12 ] |
|
Thanks Kaspars But sorry, I dont get your use case. Notice that convertToDatabaseValueSQL is called just when using queries to find a object by a especific columns which is your mapping type. |
| Comment by Kaspars Sproģis [ 29/Sep/12 ] |
|
I am using PostgreSQL tsvector data type for full text search. Here is my tsvector custom data type class: The only way to update this field in postgresql is to use postgresql function to_tsvector('some text'). public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) { return sprintf('to_tsvector(%s)', $sqlExpr); } But when i use inheritance, then by some reason convertToDatabaseValueSQL method is not called and tsv field is updated with simple text as returned by convertToDatabaseValue() method. Here is the result after persisting (for persist it failed) $person = new ItemPerson(); $person->setName('some words for test'); $em->persist($person); $em->flush(); DB Result: Name | Tsv --------------------|------------------------------------ some words for test | 'for' 'some' 'test' 'words' Here is the result after second time update (now by tsv format you can see it worked):
$person->setName('some more words for test');
$em->flush();
DB Result:
Name | Tsv
--------------------|------------------------------------
some words for test | 'test':5 'word':3
|
| Comment by Fabio B. Silva [ 30/Sep/12 ] |
|
Thanks Kaspars Now i saw the problem Writing a patch ... |
| Comment by Kaspars Sproģis [ 03/Oct/12 ] |
|
Just tested fixed version and everything works perfectly now. |
| Comment by Fabio B. Silva [ 03/Oct/12 ] |
|
Fixed by : https://github.com/doctrine/doctrine2/commit/91caff1d8965c20b72d5fdd04ffadf3ab063c1ba |