mweibel / connect-session-sequelize

Sequelize SessionStore for Express/Connect
212 stars 72 forks source link

Invalid object name 'Session'. #97

Closed UziTech closed 4 years ago

UziTech commented 4 years ago

seems latest release broke mssql because Session is a reserved word

UziTech commented 4 years ago

or because it doesn't use the table name from the already imported model

UziTech commented 4 years ago

I fixed it in my code by including the table option

  const db = new Sequelize(...)
    db.import(path.resolve(__dirname, "./models/sessions"))
- const store = new SequelizeStore({db})
+ const store = new SequelizeStore({db, table: "sessions"})

This seems like a breaking change.

mweibel commented 4 years ago

Ouch. Thanks for reporting. @durek1337 any idea what went wrong here?

@UziTech if you just do this change: https://github.com/UziTech/connect-session-sequelize/commit/f78d5388d7cb39357fa3d8609e4e322f52232199 it works again?

durek1337 commented 4 years ago

Hello, you should simply be able to use the option tableName with "Sessions". But maybe it would be better to use the default modelKey pluralized for tableName as default. That would lead in "Sessions" by default and is the way how sequelize generates tablenames as far as I remember. I will look after it when I'm back from work.

UziTech commented 4 years ago

@mweibel yes because my table is called sessions. I probably should have been using the table: "sessions" option anyway but it was working without it before v6.1.0

UziTech commented 4 years ago

I'm guessing it worked prior to v6.1.0 because the default model didn't have a tableName property and sequelize pluralized the model name by default like @durek1337 said.

The default tableName option should probably be "Sessions" to keep backwards compatibility

mweibel commented 4 years ago

Version 6.1.1 has been released. Thanks @UziTech

UziTech commented 4 years ago

Thanks for the quick response :tada: