-
Notifications
You must be signed in to change notification settings - Fork 182
Properties with mysql custom "columnName" don't get autoupdated #250
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
Comments
Great catch! Ran into the same problem myself with [email protected] For a more succinct version one could just change it to this: |
@stelescuraul Could you please submit a PR to fix this patch? Please tag me on it and I will take a look at it. |
@stelescuraul @ygaller Any updates on submitting a PR for this patch? |
@ssh24 will do it in an hour. |
@ssh24 Please check PR. |
@stelescuraul PR #255 is ready to be landed. Please submit the same patch for 3.x branch as soon as you can. |
* 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
I met with this issue 5 minutes ago in my code. :( and this fix is not full yet (especially for 3.x branch). look here: var colName = expectedColNameForModel(propName, m);
///skip some code...
//NOTICE: we call actualize with column name like "first_name"
actualize(colName, found);
///skip some code...
function actualize(propName, oldSettings) {
//BUG: try to find property not by firstName but for first_name and then newSettings will be undefined
var newSettings = m.properties[propName];
if (newSettings && changed(newSettings, oldSettings)) {
//BUG: use self.columnEscaped below
var pName = self.client.escapeId(propName);
sql.push('CHANGE COLUMN ' + pName + ' ' + pName + ' ' +
self.buildColumnDefinition(model, propName));
}
} @ssh24 can I provide PR for it? |
@darknos this is not fixed in 3.x. i will fix it in a few hours when i get home |
@stelescuraul @darknos Either one of you can do a PR for the fix on 3.x. |
ok. I just already fixed it locally but is not yet committed. :) I'll make branches for the issues. |
done. look at #273 |
* #250 fix column escaping for autoupdate * Fix lint error
Fixed in both |
Bug or feature request
If you have a model that has properties with
mysql
field andcolumnName
that is different than the model property name, then it will throw error on autoupdateDescription of feature (or steps to reproduce if bug)
Say we have a model "Users" with the following property:
Because it is save in the database as "first_name" and not "firstName" if you change the "nullable" property to "T" (true) the mysql connector throws error when doing autoupdate:
Error: ER_BAD_FIELD_ERROR: Unknown column 'firstName' in 'modelName'
Expected result
To be able to detect that the property name has a different name in the database, and use that when you call autoupdate function on the datasource.
Fix
I have followed down the flow and I managed to fix this error changing the line 310 in lib/migration.js to use the mysql property name if it is found as follows:
the above code replaces line 310. Using that, the mysql connector works fine when doing autoupdate on an existing database.
I have run the tests and they pass as expected.
Additional information (Node.js version, LoopBack version, etc)
The text was updated successfully, but these errors were encountered: