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

TypeError: str.replace is not a function at Object.snakeCase when saving entity to repository #4805

Closed
bartolomej opened this issue Sep 25, 2019 · 1 comment

Comments

@bartolomej
Copy link

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Hi! When i run await getRepository("Course").save(course) on some entity i get the following error:

TypeError: str.replace is not a function
at Object.snakeCase (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/util/StringUtils.ts:20:16)
at DefaultNamingStrategy.Object.<anonymous>.DefaultNamingStrategy.tableName (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/naming-strategy/DefaultNamingStrategy.ts:18:56)
at EntityMetadata.Object.<anonymous>.EntityMetadata.build (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/metadata/EntityMetadata.ts:787:58)
at /Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/metadata-builder/EntityMetadataBuilder.ts:94:55
at Array.forEach (<anonymous>)
at EntityMetadataBuilder.Object.<anonymous>.EntityMetadataBuilder.build (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/metadata-builder/EntityMetadataBuilder.ts:94:14)
at ConnectionMetadataBuilder.Object.<anonymous>.ConnectionMetadataBuilder.buildEntityMetadatas (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/connection/ConnectionMetadataBuilder.ts:69:113)
at Connection.Object.<anonymous>.Connection.buildMetadatas (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/connection/Connection.ts:513:59)
at Connection.<anonymous> (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/src/connection/Connection.ts:190:18)
at step (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/node_modules/tslib/tslib.js:136:27)
at Object.next (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/node_modules/tslib/tslib.js:117:57)
at fulfilled (/Users/<user>/WebstormProjects/typeorm-reproduce-bugg/node_modules/tslib/tslib.js:107:62)
at process._tickCallback (internal/process/next_tick.js:68:7)

I've created an example repository at https://github.com/bartolomej/typeorm-reproduce-bugg with steps to reproduce the described error.

@bartolomej
Copy link
Author

bartolomej commented Sep 25, 2019

I solved the issue. The problem was that i had the following entity Course:

const EntitySchema = require('typeorm').EntitySchema
const Course = require('../Course')

module.exports = new EntitySchema({
  name: 'Course',
  target: Course,
  columns: {
    uid: {
      primary: true,
      type: 'varchar'
    },
    title: {
      type: 'varchar'
    },
    description: {
      type: 'varchar'
    },
    tags: {
      type: 'varchar'
    },
    content: {
      type: 'text'
    },
    created: {
      type: 'date'
    },
  },
  relations: {
    subcategories: {
      target: "Subcategory",
      type: "many-to-many",
      joinTable: true,
      cascade: true
    }
  }
})

and I forgot to export targeted Course model at require('../Course') so the naming strategy function received an empty object, which produced TypeError: str.replace is not a function

akosasante pushed a commit to akosasante/typeorm that referenced this issue Sep 9, 2020
enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805
akosasante pushed a commit to akosasante/typeorm that referenced this issue Sep 9, 2020
…ssing name argument

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805
pleerock pushed a commit that referenced this issue Sep 26, 2020
* fix: enforce name argument of migration generate command

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: #2719, #4798, #4805

* fix: update error message text for generate migration command when missing name argument

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: #2719, #4798, #4805

Co-authored-by: Akosua Asante <akosuaasante@gmail.com>
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
… (typeorm#6690)

* fix: enforce name argument of migration generate command

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805

* fix: update error message text for generate migration command when missing name argument

enforce the type of the name argument in order to return a more useful error message when the user forgets to provide a migration name to the generate migration command

Closes: typeorm#2719, typeorm#4798, typeorm#4805

Co-authored-by: Akosua Asante <akosuaasante@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant