From f3b0cb062e7f550fd371730d2aac2696ae323980 Mon Sep 17 00:00:00 2001 From: nennad Date: Thu, 3 Sep 2015 17:00:38 +0100 Subject: [PATCH 1/2] 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 --- lib/datasource.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index 97ce57c2..fd4b54f1 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -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) { From e679deb3764af5317284f5de117ade9e0742426a Mon Sep 17 00:00:00 2001 From: nennad Date: Thu, 3 Sep 2015 17:02:21 +0100 Subject: [PATCH 2/2] typo fix --- lib/datasource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datasource.js b/lib/datasource.js index fd4b54f1..30aa27e8 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1820,7 +1820,7 @@ DataSource.prototype.defineForeignKey = function defineForeignKey(className, key if (foreignMeta.dataType) { fkDef[this.connector.name].dataType = foreignMeta.dataType; } - if (foreingMeta.dataLength) { + if (foreignMeta.dataLength) { fkDef[this.connector.name].dataLength = foreignMeta.dataLength; } }