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

many to many (through model, with extra field in junction table) error "<Model1> is not associated to <Model2>" #126

Closed
kk4fun opened this issue Jun 13, 2017 · 6 comments

Comments

@kk4fun
Copy link

kk4fun commented Jun 13, 2017

Hi. I'm new in feathersj , sequelize and web. So i'm trying to create simple first app and i need some backend for it.
Now about the current problem:
I have 3 sequelize models - receipts,ingredients and receiptsIngredients
You can see all code here (hooks, models, associations etc.)
https://github.com/kk4fun/feathers-server-receiptsmania

So , when i send get request in postman i get an error:

{
    "name": "GeneralError",
    "message": "ingredients is not associated to receipts!",
    "code": 500,
    "className": "general-error",
    "data": {},
    "errors": {}
}

And there's one note: in postgres.js file here, where associations are set i don't see this log. But it auto-generated feathers code. May be it helps.

 Object.keys(models).forEach(name => {
      if ('associate' in models[name]) {
        console.log('!!!');
        models[name].associate(models);
      }
    });

And i don't understand now what is wrong and why i can't see receipts with ingredients throw receipts service with sequelize include before hook. Help me, please :)

=======================================
I'm doing it on Windows 10 x64, in VS code editor.

@eddyystop
Copy link

eddyystop commented Jun 13, 2017

That looks like a DB error, and not from postman.

Since you are new to web development, wouldn't it be a better learning experience to start with the straightforward NeDB DB rather than with the complexity of Sequelize?

If you insist on Sequelize, I suggest you look at bestbuy/api-playground and feathersjs/api-playground-client

@kk4fun
Copy link
Author

kk4fun commented Jun 13, 2017

@eddyystop Thanks for fast reply. Can you explain why is NeDB is more simple than postgres+ sequelize?
And ofcource I'll read about it in official sources. But i want to hear your point of view too.

As i understand NeDB is lightweight MongoDB. And there's just collections instead of tables& associations.

About error: I think that looks like associations are not set properly, because when i try get for example ingredients - all is ok (ingredient service does not have include sequelize hook). But i can't understand what is wrong.
Thx for playgrounds links. I will see it soon.

@kk4fun kk4fun changed the title many to many error "<Model1> is not associated to <Model2>" many to many (through model, with extra field in junction table) error "<Model1> is not associated to <Model2>" Jun 14, 2017
@eddyystop
Copy link

Nedb uses flat files on your local system. It does not require a service to connect to. It's stupid simple to serve up. It does everything that feathers supports that's dB independent.

Yes your problem invloves associations which even experienced people can have issues with.

@kk4fun
Copy link
Author

kk4fun commented Jun 14, 2017

@eddyystop Thx for explanations about Nedb! Can you suggest some good examples with feathersjs + Nedb?

Yes your problem invloves associations which even experienced people can have issues with.

Yes, i understand it but may be you know how to fix this in my case?

Or may be , if it's associations trouble would i create issue here https://github.com/sequelize/sequelize/issues ?

@eddyystop
Copy link

I'm not familiar with sequelae. I would think the problem is with your syntax not with sequelize. Perhaps you can ask Ryan-wheel on slack.

This is the kind of situation you don't really want while learnin and why I recommended nedb.

@kk4fun
Copy link
Author

kk4fun commented Jun 14, 2017

This is the kind of situation you don't really want while learnin and why I recommended nedb.

Yes, i agree. Thanks a lot.

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

2 participants