dataloader-sequelize: .paired missing on belongsToMany association

Hi,

Not sure whether my setup or association definition is off, but it seems to work fine without dataloader-sequelize.

I have the following “user/friends” association:

User.belongsToMany(User, {as: "friends", through: "Friends"});

This works:

const user = await User.findById(1);
const friends = await user.getFriends();

console.log(`You have ${friends.length} friend(s).`);

However, adding dataloader-sequelize to the mix:

dataloaderSequelize(User);
...
...

Yields the following error:

AssertionError: .paired missing on belongsToMany association. You need to set up both sides of the association.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 18 (4 by maintainers)

Most upvoted comments

I know, I have copied the existing tests and modified the sequelize models.

On Sat, 15 Jun 2019, 20:05 Mick Hansen, notifications@github.com wrote:

@kfrajtak https://github.com/kfrajtak Your PR should only add new tests, generally don’t modify existing tests unless a behaviour is incorrect and needs to change (which would result in a semver major)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mickhansen/dataloader-sequelize/issues/23?email_source=notifications&email_token=AALQYNAWTZDO7AYODJY4K5TP2UVPXA5CNFSM4C56DTIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXY5HAA#issuecomment-502387584, or mute the thread https://github.com/notifications/unsubscribe-auth/AALQYNFLTGVSEN2AUXQIXKDP2UVPXANCNFSM4C56DTIA .

Sounds good to me @kfrajtak, PR welcome

ok i think i solved it with this.

user.friends = user.belongsToMany(models.user, {
      as: 'friends',
      through: 'friendship',
      foreignKey: 'userId',
      otherKey: 'friendId'
    })
    user.friendss = user.belongsToMany(models.user, {
      as: 'friendss',
      through: 'friendship',
      foreignKey: 'friendId',
      otherKey: 'userId'
    })