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

Count includes problem with Postgres #6328

Closed
AlexNasonov opened this issue Jul 23, 2016 · 1 comment
Closed

Count includes problem with Postgres #6328

AlexNasonov opened this issue Jul 23, 2016 · 1 comment

Comments

@AlexNasonov
Copy link

I have tried all options, mentioned in Issue#222, but still have some problems with my code:

User.belongsToMany(Role, {through: 'user_roles'});
Role.belongsToMany(User, {through: 'user_roles'});

models.Role.findAll({
                attributes:['name',
                   [models.sequelize.fn('COUNT', models.sequelize.col('users.email')), 'users']
                ],
                include: [{
                    model: models.User,
                    attributes: ['email'],
                    through: {
                        attributes: []
                    },
                    duplicating: false

                }],
                group: ['role.name']

I have Postgres and ManyToMany relation. I can't remove email attribute, because if i remove it, i get an error from through model: Unhandled rejection TypeError: Cannot set property 'user_roles' of undefined.

Without group: ['role.name'] I get Unhandled rejection SequelizeDatabaseError: column "role.name" must appear in the GROUP BY...

If I let it be, it says column "users.email" must appear in the GROUP BY...))

If I add "users.email" to group it hits with Unhandled rejection SequelizeDatabaseError: column "users.user_roles.createdAt" - as it did not remove through attributes((

And in the end, when I have group: ['role.name', 'users.email', "users.user_roles.createdAt", "users.user_roles.updatedAt", "users.user_roles.userEmail", "users.user_roles.roleName" ]. It makes a fatality with Unhandled rejection TypeError: Cannot set property 'user_roles' of undefined

@mickhansen
Copy link
Contributor

Your issue with removing email should be fixed as of master, but yes there was a bug with it.
That bug likely effectively stops you from going forward since you need to remove all regular attributes.

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