sails-generate-models
sails-generate-models copied to clipboard
attribute `primaryKey` + `model` error
I do not know why this happens, but I get two attributes at the same time: primaryKey and model.
I'm propose check before writing if primaryKey exists and delete model.
attributes: {
user_id: {
type: 'integer',
required: true,
autoIncrement: true,
primaryKey: true,
size: 11,
model: 'user'
},
In this situation sail lift causes an error:
error: A hook (
orm) failed to load! error: Error: Trying to create an association on a model that doesn't have a Primary Key.
or
error: A hook (
orm) failed to load! error: TypeError: Cannot read property 'toLowerCase' of undefined
CREATE TABLE `users` (
`user_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `users`
ADD PRIMARY KEY (`user_id`);
ALTER TABLE `users`
MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT;
For this table I have triggers and many foreign keys
ALTER TABLE `ep`
ADD CONSTRAINT `ep_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE SET NULL ON UPDATE CASCADE;
If you figure it out, feel free to submit a PR.
I know what needs to be improved in the resulting file to make the model work. I do not have time to look for where in your project you need to fix.
So either you take care of your project or you hand over the module to someone who wants to take care of it. Ex: here is an active user: https://github.com/jovanross/sails-generate-models/commits/master
@bato3 how did you imagine the "handover", if I may ask? Is the owner of a project supposed to look for forks and press themselves to find a new owner? This is an open source addition to help you, you take it or leave it, heck, you can even create PR's, and anyone can do. Can you make your own copy and develop it further? Of course, you can! But don't tell someone else what they're supposed to be doing just because you have an idea of how things should be working... Go ahead and follow jovanross and get him to do the work for you...
@bato3 TL;DR; I think you need to change your tone a bit. I don't appreciate your skewed view of what open source is.
I've published a lot of open source projects and I maintain each and every one of them actively. I simply stop actively developing on the ones I no longer use myself, which I think is fair. If I were to not answer questions and stop merging and publishing PRs you might have a point, but still only morally. Again, if you wish to contribute feel free. If you want pointers, feel free to ask as well. I'm not gone, I just don't code on them.
But don't expect me, or anyone (with the exception of projects that don't accept PRs) in the open source community for that matter to feel obligated to write code because you think we owe you something. That's just ungrateful.
Update: as to the fork of @Jovanross, that's the way open source works. He or she had a choice to make, PR or fork and decided to do the latter. While I don't condone forking maintained projects with no good reason, I don't think it's wrong either. For all I know he or she had a case that just wouldn't fit this project.
@RWOverdijk @benomatis I agree and would tell a person the same. I forked this project because I'm working with Sails v1 which has different data model formatting. May be a good idea to create a new v1 branch on this project and adding my fork to it. Either way, I'll submit a PR we can figure it out from there. However, I'm appreciative that your project already existed and I could add some minimal things to accomplish what I needed for my own.
@bato3 as much as you don't have time fork and update the code, you can't assume that others will be able drop everything and have time do so. Being a good open source citizen means respecting others' time. After all, almost all of us are doing these projects on the side and for our own benefit in some way. If you're working with Sails v1, MySQL and use referential keys in your models, feel free to give my fork a try. But I'm currently selling a house, buying a new one and my wife and I just had a new baby boy - besides my normal day job as a tech lead. Just saying...in case you ask me to fix something. 😃
@jovanross To completely destroy the topic of this issue, I want to go offtopic and congratulate you with your baby boy! 🎈 🎉
@RWOverdijk Thank you! Yes, we're off topic and it's awesome.