-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
How do you extend the models created? #204
Comments
Another issue is keeping the validations and not overwriting them. How do we do this? |
I'm operating under the assumption that this is more to kick-start a models project rather than something you'd use after establishing existing models. You can control which tables are addressed so perhaps you need to use the exclude feature to ignore tables that have been established? |
Can you provide some example code, showing how you have extended the model files? |
@steveschmitt Some examples of things you might want to always add to models: I've been thinking about this a bit, and how it'd have to look. I can't really see a way to do it besides allowing users to pass in a JSON object or similar that describes replacements/addendums to make to generated models. eg
I really can see the value in the concept (if it can be done right). It'd stop library consumers having to either manually patch models after re-generation, or writing their own scripts to do so after the fact. I'd be happy to put a POC together for it if there's appetite and consensus on how it should be implemented. |
It seems like it could be done with mixins that the developer could apply to the models at run time, similar to the way that Sequelize adds methods to the models when we use |
Another idea would be to allow the developer to write a base class that extends the Sequelize Right now, if you use
We could change that to extend a developer-defined base class, like
Or even put some wildcard so that each model gets its own base class, like
It would work about the same for ES6 classes. The developer would be responsible for writing the base class(es). The generator would have to write the |
To handle overwriting I used source version control like git ( develop or main branch has the original models ) |
Anybody have a solution for this? My project currently uses custom getters for:
Can anybody recommend an approach either within this lib, or on top of it (scripts etc)? Would love to be able to use this lib. TIA! |
Hi all -- wrote down some thoughts on a different approach here. would appreciate any insight! |
Sometimes the models themselves have functions defined, but these get overwritten by the exporter. I was thinking an option to create automatic extend classes could be useful. This is done by the MySQLWorkBench converter for sequelize as well. Can this do something similar? If you have any good suggestions for this let me know.
The text was updated successfully, but these errors were encountered: