S
S
Stanislav2019-12-23 12:37:23
Doctrine ORM
Stanislav, 2019-12-23 12:37:23

Doctrine: how to indicate that in the database the type of the field is not the same as in the entity?

There is an entity that we can read from multiple repositories. One of them is Doctrine. The id field is essentially a string type, but in the database this field is declared as an integer. How can I specify in the mapping xml-config, or somewhere else, that this field should be converted to a string when it is read from the database?
UPD: you need to change the type of fields not at runtime, not in the database itself, do alter, and so on and so forth. You just need to specify in the config that such and such a field in the database is of type int, but we must write it to the class property as a string.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2019-12-23
@Flying

Climbing into the sources of mappings for entities in Doctrine is clearly not worth it. Doctrine supports several mapping options and no one will tell you in advance which source (or sources) are used - this is determined by the Doctrine configuration.
The standard way to work with mappings at runtime is the ClassMetadata API . You can access the class metadata factory through EntityManager::getMetadataFactory()either, if you are interested in a specific entity, through EntityManager::getClassMetadata().
The object ClassMetadataInfocontains information about all the mapping details of a particular entity. Most of its properties are declared as public for faster access, although writing there, of course, is prohibited.
The class is very large, so the easiest way to look at its contents is either in the debugger or through some kind of dump. Specifically, the mapping's of the fields are in the $fieldMappings variable .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question