Is it possible to specify a column type of unsigned integer
in Doctrine 2?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Doctrine 1 documentation and Doctrine 2 documentation said you can do it by this ways:
PHP annotations:
Yaml: (see docs)
Hope this helps to someone to save a time ;)
Decimals will allow for such large numbers and allow you to keep the SchemaTool, just set the scale to 0.
Checkout a full writeup on why here. [EDIT](link does not work) I have pasted the article below. It was written by me anyways ;)
unsigned numbers so large your brain will explode! w/Doctrine 2
ORMs have an inherent problem. How do you take a datatype only some RDBMSs support and allow you to use it anyways. Well when it comes to Doctrine 2 and unsigned numbers they got a little lazy.
All I want to do is store my 64bit facebook IDs. How hard is that? Well my RDBMS is mySQL so all I really need is an unsigned bigint.
This seems find and dandy until you read this:
columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows to make use of advanced RMDBS features. However you should make careful use of this feature and the consequences. SchemaTool will not detect changes on the column correctly anymore if you use “columnDefinition”. Basically this feature let’s you free form unsupported things into the column definition. Making unsigned numbers technically UN-SUPPORTED! Not to mention my dev and QA deployment systems rely heavily on the SchemaTool. We can thank a combination of lazy developers at Doctrine and sqlite3 for this little nugget of crazy town.
This immediately prompted a google search. I don’t like thinking if I don’t have to. What did I find? Everybody’s using varchars. VARCHARS!?!? I about had a heart attack. That was just unacceptable.
Thus enters decimal. It’s perfect. The storage size is variable and it’s stored in binary so indexing is super fast. We just set the decimal precision to zero and voilà. The ORM can port this to any RDBMS, it’s big enough for us not to care about the unsupported signed/unsigned issue and it’s lightning fast. decimal(20,0) should handle our facebook size of eighteen quintillion four hundred and forty six quadrillion seven hundred and forty four trillion seventy three billion seven hundred and nine million five hundred and fifty one thousand six hundred and fifteen quite nicely.
You can but you will loose portability. Use
columnDefinition
attribute and set it tointeger unsigned
. The actual code depends on what you are using.There is no place in the doc (that I've seen) that speak about this, but it works.
Update
Definition in Yaml (as of 2.4 for primary key)