Sequelize-Auto Override for MySQL View

12 Views Asked by At

I am generating a model with the sequelize-auto library and I am having trouble working with MySQL Views.

I have created a view and am generating a sequelize model from it. This view does not have a column called id. MySQL also does not allow for views to define primary keys. Because of how sequelize works, any model without a specific primary key defined, will have an id column added. This breaks the generated model.

I can fix this simply by amending my model by adding primaryKey flags to the fields that constitute a unique entry in the view. However, these changes will be overwritten each time I generate the model using sequelize-auto.

sequelize-v7-alpha adds the ability to define tables as having no primary key. So using MySQL views with v6 may be a specific limitation of the library.

What I would like to do is simply add some type of model override where after generating the sequlize-auto model from my database, I can specify what columns of what models to add properties to. However, I can't figure out any configuration that will do so. Does anyone know how to do this or a workaround for this type of situation?

0

There are 0 best solutions below