loopback-connector-postgresql
loopback-connector-postgresql copied to clipboard
Properties with underscores in their name cannot be indexed
Steps to reproduce
- create a model with a property name that contains an underscore in it (e.g. short_name).
- set that property to be indexed (e.g.
"index": true
) - call
pg.autoupdate()
(e.g. whereapp.datasources.pg
);
Current Behavior
- The index is added
- Then the index is dropped
Expected Behavior
- The index is added
Additional information
The bug shown here is a bad regular expression in migration.js (on or about line 777):
const propNameRegEx = new RegExp('^' + self.table(model) + '_([^_]+)_idx');
The simple fix is:
const propNameRegEx = new RegExp('^' + self.table(model) + '_(.*)(?:_idx)$');
@ewrayjohnson, would you be interested to submit a PR?
A workaround would be to specify a "valid" column name in the @property
decorator. See https://github.com/dhmlau/loopback4-example-todo-customized#if-i-have-a-table-name-or-column-name-that-is-different-from-the-model-name-and-property-what-should-i-change for an example. Thanks.
A workaround would be to specify a "valid" column name in the
@property
decorator. See https://github.com/dhmlau/loopback4-example-todo-customized#if-i-have-a-table-name-or-column-name-that-is-different-from-the-model-name-and-property-what-should-i-change for an example. Thanks.
For those of us that have not taken the leap to LoopBack 4, the @property decorator is not an option. Instead we would have to use postgresql.columnName
@ewrayjohnson, would you be interested to submit a PR?
Yes
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.