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
constscopes={public: {attributes: {exclude: ['secret']}}}// imagine i made a model named User with two fields:// - secret// - nameUser.belongsTo(City)// user now has cityId fieldUser.scope('public').findById(123).then((user)=>// user === { id: 123, name: 'Bob' })
What do you expect to happen?
The foreign key cityId should exist on the result
What is actually happening?
The foreign key cityId does not exist on the result
When not using scopes, cityId appears in the result as expected.
Dialect: postgres Sequelize version: 3.23.4
Reacted by Toni Villena, raf, MH3009, Theophile Morin, leo21, JB Gosselin, Alexis Benoist and Rovack
I'm pretty sure this happens because scopes are converted from attributes: { include, exclude } to attributes: [..] when the model is defined - at which point the foreign keys have not been added yet
varSequelize=require('./index');varsequelize=require('./test/support').createSequelizeInstance();// boilerplateconstCity=sequelize.define('city',{name: Sequelize.STRING})constUser=sequelize.define('user',{name: Sequelize.STRING,secret: Sequelize.STRING},{scopes: {public: {attributes: {exclude: ['secret']}}}})User.belongsTo(City)constmakeCity=()=>City.create({name: 'Test'})constmakeUser=()=>makeCity().then((city)=>User.create({name: 'Bob',city: city}))// actual problem, code exactly the same as first commentmakeUser().then((ourUser)=>{User.scope('public').findById(ourUser.id).then((user)=>// user === { id: 123, name: 'Bob' })})
For the record, it's really cumbersome to go through this SSCE (what does this even stand for?) rigmarole for an issue this simple to repro - might be worth revisiting this policy. Seems like a serious deterrent for people who want to report bugs and contribute on issues.
I'm having this issue when trying to define a defaultScope that uses exclude in attributes. @felixfbecker is there a way to use addScope to modify the defaultScope? Trying to override it with addScope('defaultScope') doesn't seem to work.
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 🙂
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 🙂
Activity
mickhansen commentedon Jul 8, 2016
That's highly odd, can you post a full SSCCE? https://github.com/sequelize/sequelize/blob/master/sscce_template.js
janmeier commentedon Jul 8, 2016
I'm pretty sure this happens because scopes are converted from
attributes: { include, exclude }toattributes: [..]when the model is defined - at which point the foreign keys have not been added yetyocontra commentedon Jul 9, 2016
@janmeier That would explain it if that's how things are implemented in sequelize
yocontra commentedon Sep 12, 2016
SSCE:
For the record, it's really cumbersome to go through this SSCE (what does this even stand for?) rigmarole for an issue this simple to repro - might be worth revisiting this policy. Seems like a serious deterrent for people who want to report bugs and contribute on issues.
yocontra commentedon Nov 3, 2016
Any word on this? Didn't get a response - pretty major bug.
felixfbecker commentedon Nov 3, 2016
@contra Could you try first defining the model, then associating, and then using
addScope()to add the scope?yocontra commentedon Nov 3, 2016
@felixfbecker That fixes it
felixfbecker commentedon Nov 3, 2016
Great. The only real fix I think would be to store the scopes raw and normalize JIT, but that might have have a small performance impact.
yocontra commentedon Nov 12, 2016
@felixfbecker Sounds good to me
tonivj5 commentedon Jan 23, 2017
I use a function instead of objects and it works 👍
An example:
scottbeacher commentedon May 1, 2017
I'm having this issue when trying to define a defaultScope that uses
excludeinattributes. @felixfbecker is there a way to useaddScopeto modify the defaultScope? Trying to override it withaddScope('defaultScope')doesn't seem to work.DMan577 commentedon May 1, 2017
You need to pass
{override: true}to the 3rd parameter ofaddScopeto override it.addScope('defaultScope', {...}, {override:true}scottbeacher commentedon May 1, 2017
That worked, thank you.
stale commentedon Jun 30, 2017
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 🙂
2 remaining items
stale commentedon Aug 30, 2017
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 🙂
yocontra commentedon Aug 30, 2017
Still an issue.
stale commentedon Sep 29, 2017
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 🙂
tonivj5 commentedon Sep 29, 2017
stale commentedon Dec 28, 2017
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 🙂
yocontra commentedon Dec 28, 2017
Keep it open. Can we get any response here to get rid of this stale bot? I've bumped this for months and the ticket has been open for 1.5 years.
sushantdhiman commentedon Oct 28, 2018
Fixed by 88a340d