-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ function mixinMigration(MySQL, mysql) { | |
}); | ||
} | ||
if (found) { | ||
actualize(colName, found); | ||
actualize(propName, found); | ||
} else { | ||
sql.push('ADD COLUMN ' + self.client.escapeId(colName) + ' ' + | ||
self.buildColumnDefinition(model, propName)); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ... ten lines above we use please, confirm the change and, please, explain the reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. But what I am not understanding is, if we specify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like this?
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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;
}; |
||
sql.push('CHANGE COLUMN ' + pName + ' ' + pName + ' ' + | ||
self.buildColumnDefinition(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.
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)