Skip to content
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

Properties with underscores in their name cannot be indexed #462

Open
ewrayjohnson opened this issue Oct 7, 2020 · 6 comments
Open

Properties with underscores in their name cannot be indexed #462

ewrayjohnson opened this issue Oct 7, 2020 · 6 comments

Comments

@ewrayjohnson
Copy link

ewrayjohnson commented Oct 7, 2020

Steps to reproduce

  1. create a model with a property name that contains an underscore in it (e.g. short_name).
  2. set that property to be indexed (e.g. "index": true)
  3. call pg.autoupdate() (e.g. where app.datasources.pg);

Current Behavior

  1. The index is added
  2. Then the index is dropped

Expected Behavior

  1. 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 ewrayjohnson changed the title Properties with underscores in the name cannot be Properties with underscores in their name cannot be indexed Oct 7, 2020
ewrayjohnson added a commit to ewrayjohnson/loopback-connector-postgresql that referenced this issue Oct 7, 2020
@dhmlau
Copy link
Member

dhmlau commented Oct 10, 2020

@ewrayjohnson, would you be interested to submit a PR?

@dhmlau
Copy link
Member

dhmlau commented Oct 10, 2020

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.

@ewrayjohnson
Copy link
Author

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.

@ewrayjohnson
Copy link
Author

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
Copy link
Author

@ewrayjohnson, would you be interested to submit a PR?

Yes

@stale
Copy link

stale bot commented Dec 19, 2020

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.

@stale stale bot added the stale label Dec 19, 2020
@stale stale bot removed the stale label Jan 29, 2021
ewrayjohnson added a commit to ewrayjohnson/loopback-connector-postgresql that referenced this issue Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants