You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//User Modelmodule.exports=db=>{constUser=db.define('user',{firstName: {type: STRING},},{scopes: {friends: function(){return{through: {where: {accepted: true}}}}}})returnUser}module.exports.associations=(User)=>{User.belongsToMany(User,{through: Friendship,as: 'friends'})}//Friendship Modelmodule.exports=db=>{constFriendship=db.define('friendship',{accepted: {type: BOOLEAN,defaultValue: false},originalRequest: {type: BOOLEAN,defaultValue: false}},)returnFriendship}//this works correctly and returns only friends where accepted = truerouter.get('/',asyncHandler(async(req,res,next)=>{constfriends=awaitreq.requestedUser.getFriends({through: {where: {accepted: true}},logging: console.log})res.json(friends)}))//this does not workrouter.get('/',asyncHandler(async(req,res,next)=>{constfriends=awaitreq.requestedUser.getFriends({scope: 'friends',logging: console.log})res.json(friends)}))
What do you expect to happen?
Hello all I am trying to query based on a condition from the through table where Users are related to Users through friendship. It seems to work correctly but I couldn't find this option in the docs anywhere. Is this a new feature or can someone link to where it is mentioned? I was trying to apply a scope which would return a query from the through table but that does not work correctly. Any reason this would work one way but not the other?
What is actually happening?
The query is working with the through condition but not with the scope. Looking for information on querying the through table based on association methods & also curious how to apply scope to a through table.
Dialect: Postgres Sequelize version: 5.0.0-beta.10 Tested with latest release: Yes (If yes, specify that version)
Note :Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
What are you doing?
What do you expect to happen?
Hello all I am trying to query based on a condition from the through table where Users are related to Users through friendship. It seems to work correctly but I couldn't find this option in the docs anywhere. Is this a new feature or can someone link to where it is mentioned? I was trying to apply a scope which would return a query from the through table but that does not work correctly. Any reason this would work one way but not the other?
What is actually happening?
The query is working with the through condition but not with the scope. Looking for information on querying the through table based on association methods & also curious how to apply scope to a through table.
Dialect: Postgres
Sequelize version: 5.0.0-beta.10
Tested with latest release: Yes (If yes, specify that version)
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
The text was updated successfully, but these errors were encountered: