Fix foreignKey length issue

If the PK has a definition like
```
      "mysql": {
        "dataType": "CHAR",
        "dataLength":36,
        "nullable":"N"
      }
```

dataLength is ignored when the PK is used as a foreignKey in other models
This commit is contained in:
nennad 2015-09-03 17:00:38 +01:00
parent c4de830bfe
commit f3b0cb062e
1 changed files with 7 additions and 2 deletions

View File

@ -1815,9 +1815,14 @@ DataSource.prototype.defineForeignKey = function defineForeignKey(className, key
var fkDef = {type: pkType};
var foreignMeta = this.columnMetadata(foreignClassName, pkName);
if(foreignMeta && foreignMeta.dataType) {
if (foreignMeta && (foreignMeta.dataType || foreignMeta.dataLength)) {
fkDef[this.connector.name] = {};
fkDef[this.connector.name].dataType = foreignMeta.dataType;
if (foreignMeta.dataType) {
fkDef[this.connector.name].dataType = foreignMeta.dataType;
}
if (foreingMeta.dataLength) {
fkDef[this.connector.name].dataLength = foreignMeta.dataLength;
}
}
if (this.connector.defineForeignKey) {
var cb = function (err, keyType) {