-
-
Save levity/02052edd445b68174c1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
attributes: { | |
name: 'string', | |
slug: 'string', | |
users: { | |
collection: 'user', | |
via: 'communities', | |
through: 'communityuser' | |
} | |
}, | |
autoCreatedAt: false, | |
autoUpdatedAt: false | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
tableName: 'users_community', | |
tables: ['communities', 'users'], | |
junctionTable: true, | |
attributes: { | |
name: 'string', | |
email: 'string', | |
users: { | |
columnName: 'users_id', | |
type: 'integer', | |
foreignKey: true, | |
references: 'user', | |
on: 'id', | |
via: 'communities', | |
groupBy: 'user' | |
}, | |
communities: { | |
columnName: 'community_id', | |
type: 'integer', | |
foreignKey: true, | |
references: 'community', | |
on: 'id', | |
via: 'users', | |
groupBy: 'community' | |
} | |
}, | |
autoCreatedAt: false, | |
autoUpdatedAt: false | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- this is what happens when i load /community/9/users. | |
-- the problem is that 2 of the users are in many communities, | |
-- and that inner join causes one row for each community they're in. | |
-- so the result set only has 2 distinct users when there should be 30. | |
-- | |
-- duplicates are being removed at some point in the code, but the | |
-- limit should be applied after that, not before. | |
SELECT | |
"user"."name", | |
"user"."email", | |
"user"."id", | |
"users_community"."community_id" AS "___community_id" | |
FROM "users" AS "user" | |
INNER JOIN "users_community" ON "users_community"."users_id" = "user"."id" | |
WHERE "user"."id" IN ( | |
SELECT "users_community"."users_id" | |
FROM "users_community" | |
WHERE "users_community"."community_id" = '9' | |
) LIMIT 30 OFFSET 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
attributes: { | |
name: 'string', | |
email: 'string', | |
communities: { | |
collection: 'community', | |
via: 'users', | |
through: 'communityuser' | |
} | |
}, | |
tableName: 'users', | |
autoCreatedAt: false, | |
autoUpdatedAt: false | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Were you able to solve this issue? Also, have you had luck actually posting to
POST /community/:id/users
? I'm finding that I have to set these routes up myself; have not had any luck getting Waterline to handle it natively.