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

destroy and findOne returning all instances #79

Open
AbreezaSaleem opened this issue Jan 9, 2020 · 0 comments
Open

destroy and findOne returning all instances #79

AbreezaSaleem opened this issue Jan 9, 2020 · 0 comments

Comments

@AbreezaSaleem
Copy link

AbreezaSaleem commented Jan 9, 2020

I have created my model like this

const SequelizeMock = require('sequelize-mock');\n const DBConnectionMock = new SequelizeMock(); const SiteTag = DBConnectionMock.define('SiteTag',{ instanceMethods: { getSiteId: function () { return this.get('siteId'); }, getTag: function () { return this.get('tag'); }, }, }); SiteTag.$queueResult([ SiteTag.build({ siteId: 1, tag: 'First tag', }), SiteTag.build({ siteId: 2, tag: 'Second tag', }), ]); module.exports.SiteTag = SiteTag;

And later I want to delete the instance with the siteId 2. I have written this code

const destroyed = await SiteTag.destroy({where: {siteId: input.id}});

and this is what destroyed contains:

[ fakeModelInstance { options: { timestamps: true, paranoid: undefined, createdAt: undefined, updatedAt: undefined, deletedAt: undefined, isNewRecord: true }, _values: { instanceMethods: [Object], siteId: 1, tag: 'First tag', id: 1, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, dataValues: { instanceMethods: [Object], siteId: 1, tag: 'First tag', id: 1, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, hasPrimaryKeys: true, __validationErrors: [] }, fakeModelInstance { options: { timestamps: true, paranoid: undefined, createdAt: undefined, updatedAt: undefined, deletedAt: undefined, isNewRecord: true }, _values: { instanceMethods: [Object], siteId: 2, tag: 'Second tag', id: 2, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, dataValues: { instanceMethods: [Object], siteId: 2, tag: 'Second tag', id: 2, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, hasPrimaryKeys: true, __validationErrors: [] } ]

I am still getting the instance with siteId 2... can someone please explain to me what I am doing wrong?

I am getting the same result when I use SiteTag.findOne({where: {siteId: input.id}});

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

1 participant