What is the syntax for “options” in the Doctrine 2.1 @Column annotation?

I am trying to define a column in Doctrine 2.1 (using annotations) that maps to a fixed-length CHAR column in MySQL. Using fixed = true does not do the job. Annotations

* @ORM\Column(type="string", length=49, fixed=true, nullable=false) 

this results in the error: "The @ORM \ Column annotations declared in the [name here] property do not have a property with the name" fixed ". Available properties: name, type, length, precision, scale, unique, options, columnDefinition." Therefore, I assume that the "fixed" bit should be transmitted in the "options". But how? I have looked at the Doctrine 2.1 documentation and cannot find anything.

I tried

 * @ORM\Column(type="string", length=49, options="fixed=true", nullable=false) 

which does not lead to an error, but is ignored - the created column is VARCHAR (49).

I would prefer not to use columnDefinition.

Any suggestions?

thanks

+6
source share
2 answers

The correct syntax is as follows:

 @ORM\Column(type="string", length=49, options={"fixed":true}, nullable=false) 
+7
source

Adding a FIXED type to your annotations will require a custom function in Doctrine. The documentation on how to set them up is fairly readable.

There is also a library of MySQL query functions in the Benjamin Eeberlei DoctrineExtensions repository, which may be useful for expanding Doctrine's own capabilities to account for MySQL-specific features.

Unfortunately, it does not include the data type you are looking for, but it can be useful as a model for customizing what you need. Good luck and please write if you find a solution that works for you.

0
source

Source: https://habr.com/ru/post/900132/


All Articles