Reputation: 2960
I'm trying to define a column in Doctrine 2.1 (using annotations) that maps to a fixed length CHAR column in MySQL. Using fixed=true doesn't do the job. The annotation
* @ORM\Column(type="string", length=49, fixed=true, nullable=false)
it results in an error: "The annotation @ORM\Column declared on property [name here] does not have a property named "fixed". Available properties: name, type, length, precision, scale, unique, nullable, options, columnDefinition". So I'm assuming that the "fixed" bit needs to be passed in "options". But how? I've scoured the Doctrine 2.1 documentation and cannot find anything on this.
I tried
* @ORM\Column(type="string", length=49, options="fixed=true", nullable=false)
which doesn't result in an error, but is ignored -- the column created is VARCHAR (49).
I'd prefer not to use columnDefinition.
Any suggestions?
THANKS
Upvotes: 6
Views: 4498
Reputation: 191
The correct syntax is this:
@ORM\Column(type="string", length=49, options={"fixed":true}, nullable=false)
Upvotes: 9
Reputation: 25005
Adding a FIXED data type to your annotations will require a user-defined function in Doctrine. The documentation on how to set these up is pretty readable.
There is also a library of MySQL query functions in Benjamin Eeberlei's DoctrineExtensions repository that you might find helpful for extending the native capabilities of Doctrine to accommodate MySQL-specific features.
Unfortunately it doesn't include the data type you're looking for, but it may be helpful as a model for setting up what you need. Good luck and please post if you find a solution that works for you.
Upvotes: 0