-
Notifications
You must be signed in to change notification settings - Fork 182
Properties with mysql custom "columnName" don't get autoupdated #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
Can one of the admins verify this patch? |
2 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
@@ -186,7 +186,7 @@ function mixinMigration(MySQL, mysql) { | |||
function actualize(propName, oldSettings) { | |||
var newSettings = m.properties[propName]; | |||
if (newSettings && changed(newSettings, oldSettings)) { | |||
var pName = self.client.escapeId(propName); | |||
var pName = self.columnEscaped(model, propName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to var pName = (newSettings.mysql && newSettings.mysql.columnName) || self.client.escapeId(propName);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in this case columnName will be not escaped and we have possible issue with columnName like from
because SQL will be like CHANGE COLUMN from from ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to merge this PR asap, but why do you want to replace documented and widely used self.columnEscaped
to that.
... ten lines above we use var colName = expectedColNameForModel(propName, m);
for the same result.
please, confirm the change and, please, explain the reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. But what I am not understanding is, if we specify the columnName
explicitly to be something different than the property name, how would this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this?
var colName = newSettings.mysql && newSettings.mysql.columnName || self.client.escapeId(propName);
var pName = self.columnEscaped(model, colName);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var pName = self.client.escapeId(newSettings.mysql && newSettings.mysql.columnName || propName);
do the same as
var pName = self.columnEscaped(propName);
/**
* Get the escaped column name for a given model property
* @param {String} model The model name
* @param {String} property The property name
* @returns {String} The escaped column name
*/
SQLConnector.prototype.columnEscaped = function(model, property) {
return this.escapeName(this.column(model, property));
};
/**
* Get the column name for the given model property. The column name can be
* customized at the model property definition level as `column` or
* `columnName`. For example,
*
* ```json
* "name": {
* "type": "string",
* "mysql": {
* "column": "NAME"
* }
* }
* ```
*
* @param {String} model The model name
* @param {String} property The property name
* @returns {String} The column name
*/
SQLConnector.prototype.column = function(model, property) {
var prop = this.getPropertyDefinition(model, property);
var columnName;
if (prop && prop[this.name]) {
columnName = prop[this.name].column || prop[this.name].columnName;
if (columnName) {
// Explicit column name, return as-is
return columnName;
}
}
columnName = property;
if (typeof this.dbName === 'function') {
columnName = this.dbName(columnName);
}
return columnName;
};
@@ -176,7 +176,7 @@ function mixinMigration(MySQL, mysql) { | |||
}); | |||
} | |||
if (found) { | |||
actualize(colName, found); | |||
actualize(propName, found); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we have a way how to find column name by property name but not vise versa.
I explained it here #250 (comment)
@slnode ok to test |
@slnode test please |
* Fixed the different column name in datasource Issue #250 * Added test to change the nullable property * moved the code from the function into test block
@darknos Thank you for taking the initiative and submitting this patch. |
* Tests for datetime types (Kevin Delisle) * Add new type DateString to fromColumnValue (Buck Bito) * Remove String manipulations of Date objects (Buck Bito) * Properties with mysql custom "columnName" don't get autoupdated (#273) (Sergey Nosenko) * Revert PR #257 (#266) (Sakib Hasan) * Fix async.each in migration (#262) (Benjamin Schuster-Boeckler) * refactor date, timestamp and datetime data types handling (#257) (Sergey Nosenko) * Fix too many connection error (#261) (Sakib Hasan)
Description
#250 for 3.x
connect to #250
Checklist
guide