Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 2.3
-
Fix Version/s: None
-
Component/s: Schema Managers
-
Labels:None
Description
Before commenting, I've done so much debugging and searching into this issue and if I missed something major, I apologise.
From what I understand, the ORM doesn't care about unsigned. That's fair enough. That leaves it to DBAL to handle it.
However, it's not possible to successfully use something like the following table without having the schema manager complain.
CREATE TABLE `account` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '(DC2Type:unsigned_integer)', `user_id` int(10) unsigned DEFAULT NULL COMMENT '(DC2Type:unsigned_integer)', PRIMARY KEY (`id`), KEY `IDX_7D3656A461220EA6` (`user_id`) ) ENGINE=InnoDB
In that code, I'm using a custom type "unsigned_integer" that extends the DBAL integer type with this:
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$fieldDeclaration['unsigned'] = true;
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
}
The reason for this is because the ORM won't map unsigned ints for me. Combined with this is an event listener for the class metadata. Something like this:
/**
* Maps additional metadata.
*
* Specifically, if there exist an unsigned integer field, attach the
* "unsigned" option to it. This is required because the Doctrine ORM does
* not do this and we are using "UNSIGNED INT"s in our MySQL columns.
* Without this. the Doctrine Schema Tool will complain about column
* differences.
*
* Note: there is no performance impact in doing this because the class
* metadata should be cached after the first request.
*
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
foreach ($eventArgs->getClassMetadata()->fieldMappings as &$mapping) {
if (isset($mapping['type']) && UnsignedIntegerType::UNSIGNED_INTEGER === $mapping['type']) {
if (!isset($mapping['options'])) {
$mapping['options'] = array();
}
$mapping['options']['unsigned'] = true;
}
}
}
Now, in the example table above, the schema tool will honour the "id" column, however it won't honour the association join column no matter what I do. My attempts include adding an event listener for class meta data as above (basically tricking the ORM) and also adding an event listener for the schema events.
The other day on GitHub there was a commit (https://github.com/doctrine/doctrine2/commit/a27be2fab61b1cfde4d2ecbc729a4a68816fca76) to help with this, but it's still not all working.
Also, comments and issues on the Jira tracker have said how there's legacy code related to "unsigned" and "default", but I can't tell what's legacy and what's allowed, especially when there's a commit like that one above.
By the way, I have found that the simple unsigned field mapping works. E.g.:
fields:
counter:
type: integer
column: counter
options:
unsigned: true
If it helps at all, here's the YAML mapping file for the above table/entity:
Account:
type: entity
table: account
id:
id:
type: unsigned_integer
generator:
strategy: AUTO
manyToOne:
creator:
targetEntity: User
joinColumn:
name: user_id
referencedColumnName: id # Note: user table id is also unsigned_integer
Is it possible to 1) fix this or 2) let me know if I'm just doing something wrong?
Note: as I said above, I know that Doctrine DBAL and ORM does not care so much for unsigned ints because of portability, etc. but it seems that because of that commit above (24 days ago), there's a half-implememented/legacy solution going on here.
Cheers,
Jon
Activity
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |