Skip to content

Fix count queries with includes - #6190

Merged
janmeier merged 1 commit into
sequelize:v3from
fintura:master
Jul 5, 2016
Merged

janmeier merged 1 commit into
sequelize:v3from
fintura:master

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Jun 30, 2016 •

Copy link
Copy Markdown
Contributor

Pull Request check-list

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does your issue contain a link to existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Have you added an entry under Future in the changelog?

Description of change

Currently the count and findAndCount and diverge in the build queries with the same query object. This unifies those two, removes unnecessary duplicated checks and fixes a bug which quite a few people ran into by optimistically removing all includes for performance reasons.

I want to have fast queries but primarily stability is important. I'm willing to have a look at this in more detail to improve the performance later.

Fixes #1142 #2145 #2968 #3936 #4146 #4194 #5526 #5680 #6123 (I went through to many issues to always be certain but likely all get fixed by this).
Fixes partly #2886 #3319 #4737 #5465 (people that commented had similar issues or a part of the issue is fixed with this)
Somehwat related #2713

I know there should be tests included and I'll add them as soon as you're happy with the other code.

@janmeier

janmeier commented Jul 1, 2016

Copy link
Copy Markdown
Member

Yeah, this "optimization" is causing too many problems to many sense - Lets KISS ;)

@BridgeAR

BridgeAR commented Jul 3, 2016

Copy link
Copy Markdown
Contributor Author

I backported all the comments from the v4 branch and included the attributes fix too.

Add changelog entry
@janmeier
janmeier merged commit 57c8a72 into sequelize:v3 Jul 5, 2016
misgina pushed a commit to ChurchDesk/sequelize that referenced this pull request Jul 28, 2016
@netdragonboberb

netdragonboberb commented Oct 14, 2016 •

Copy link
Copy Markdown

This isn't quite done, since it clashes with typescript. 'distinct' works now in findAndCountAll for 3.24.3, but it was never added to FindOptions so Typescript compiler complains since distinct is in CountOptions. Perhaps there should be a FindAndCountOptions? But the error can be ignored (I think?) since distinct makes the count returned by findAndCountAll correct.

xxxx\xxx\xxxx.ts(229,17): error TS2345: Argument of type '{ include: (TimeZoneModel | { model: UnitModel; as: string; include: any; attributes: string[]; }...' is not assignable to parameter of type 'FindOptions'.
Object literal may only specify known properties, and 'distinct' does not exist in type 'FindOptions'.

Edit: I found a workaround to get rid of the annoying Typescript error for distinct not being in FindOptions - create a new object typed to :any and then pass that to findAndCountAll e.g.

let sequelizeQuery:any = {include: [...
],
...
distinct: true
};
this._model.Sites.findAndCountAll(sequelizeQuery,
).

@alitaheri

Copy link
Copy Markdown
Contributor

@netdragonboberb This is not a typescript project. Please open issue on https://github.com/DefinitelyTyped/DefinitelyTyped, that's where the type definitions are maintained.

@felixfbecker

Copy link
Copy Markdown
Contributor

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

Successfully merging this pull request may close these issues.

5 participants