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

add support for basic findOne with ID #147

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

intellix
Copy link
Contributor

@intellix intellix commented Mar 25, 2024

Noticed that a few developers of our project were surprised that findOne didn't work until I swapped them to findByPk. Figured I'd have a go to see how much effort it was.

Next step would be adding support for cases like:

findOne({
  where: {
    id: 1,
    status: 'active'
  }
});

Which would probably cause a lot more of our codebase to use the dataloader.

  • Updated docker-compose file format (wasn't working for me locally without updating it)
  • Added support for basic findOne({ where: { id: 123 } }) usages.

For the tests, I copied findByPk and then made changes, and added an extra test that adding status: 'active' short circuits from the shim (until we add support for it).

@intellix
Copy link
Contributor Author

intellix commented Mar 25, 2024

marking as draft for now until I fix the package-lock.json format and stop prettier running (and maybe tests pass).

Is the status: 'active' case easy? I feel like it's the same loader because the only thing that would change would be the ID

@mickhansen
Copy link
Owner

marking as draft for now until I fix the package-lock.json format and stop prettier running (and maybe tests pass).

Is the status: 'active' case easy? I feel like it's the same loader because the only thing that would change would be the ID

Hm, I suppose it would not be too difficult to extract the primary key parameter and then try to determine what where clauses are equal.

@intellix intellix force-pushed the dataloader-sequelize-find-one branch from 0ab3a3a to 0e2fe55 Compare April 7, 2024 11:13
@intellix intellix force-pushed the dataloader-sequelize-find-one branch from 0e2fe55 to 92dd0cf Compare April 7, 2024 11:47
@intellix
Copy link
Contributor Author

intellix commented Apr 7, 2024

struggling to get the tests to pass for Sequelize 3 which has some weird prototyping stuff when it comes to spying on findAll (findOne calls Model.prototype.findAll). It's being called but the spy doesn't run. Everything passes in 4, 5, 6.

This is where the findAll is called, but it's not the spy instance: https://github.com/sequelize/sequelize/blob/v3.31.1/lib/model.js#L1527-L1530

versus how it works in v4 where it doesn't call it from prototype and it's the actual spy instance: https://github.com/sequelize/sequelize/blob/v4.44.4/lib/model.js#L1752-L1755

Do we need/want to support Sequelize 3? since it's more than 7 years old

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.

2 participants