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

Cannot get it work with belongsToMany associations. #3

Closed
jesusbv opened this issue Oct 6, 2015 · 5 comments
Closed

Cannot get it work with belongsToMany associations. #3

jesusbv opened this issue Oct 6, 2015 · 5 comments

Comments

@jesusbv
Copy link

jesusbv commented Oct 6, 2015

I set the through relation with

Country.belongsToMany(Article, {
        as: 'articles',
        through: {
          model: 'CountryArticle'
        },
        foreignKey: {
          name: 'countryId',
          as: 'articles'
        }
    });

  Article.belongsToMany(Country, {
      as: 'countries',
      through: {
        model: 'CountryArticle'
      },
      foreignKey: {
        name: 'articleId',
        as: 'countries'
      }
    });

It creates the through model and if I do
POST /country/uuid/articles?attribute=Value...

populate the article table but not the through model

@jesusbv jesusbv changed the title New issue Cannot get it work with belongsToMany associations. Cannot get it work with belongsToMany associations. Oct 6, 2015
@cesardeazevedo
Copy link
Owner

I've not tested with belongsToMany, i'll take a look.

@jesusbv
Copy link
Author

jesusbv commented Oct 6, 2015

@cesardeazevedo
Copy link
Owner

This is actually a fork from the original sails / waterline blueprints, and even waterline doesn't support through associations http://sailsjs.org/documentation/concepts/models-and-orm/associations/through-associations, so it will require a different implementation to support it.

for now, i suggest you to create an additional model as an intermediary instead of using through association.

@jesusbv
Copy link
Author

jesusbv commented Oct 6, 2015

Thanks. How would it be the relations?
ModelA hasMany throughModel
ModelB hasMany throughModel

throughModel belongsTo ModelA
throughModel belongsTo ModelB?

with FK tableIdA and tableIdB.
UPDATE
just read the link. Thank you.

@cesardeazevedo
Copy link
Owner

#10

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