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

[Feature] Add findByPks convenience method #11297

Open
ustun opened this issue Aug 8, 2019 · 12 comments
Open

[Feature] Add findByPks convenience method #11297

ustun opened this issue Aug 8, 2019 · 12 comments
Labels
existing workaround For issues. There is a known workaround for this issue. good first issue For issues. An issue that is a good choice for first-time contributors. type: feature For issues and PRs. For new features. Never breaking changes.

Comments

@ustun
Copy link

ustun commented Aug 8, 2019

A common thing we do is searching for model that match a given id set. This is not that hard with the following clause: Model.findAll({where: {id: {[Op.in]: [1, 2, 3]}}}), however it might be easier if a findByPks method was added so that one would do Model.findByPks([1,2,3]) and/or Model.findByPks(1,2,3).

Rails has this: https://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-find

TypeORM has this: https://typeorm.io/#/entity-manager-api Search for findByIds

I think if this will be added, we should investigate what other convenience methods could be added. For example, there is an open issue about adding exists: #10187

@ustun ustun changed the title Add findByPks convenience method [Feature] Add findByPks convenience method Aug 8, 2019
@papb papb self-assigned this Aug 8, 2019
@papb papb added existing workaround For issues. There is a known workaround for this issue. status: understood For issues. Applied when the issue is understood / reproducible. type: feature For issues and PRs. For new features. Never breaking changes. labels Aug 8, 2019
@fboechats
Copy link

fboechats commented Aug 21, 2019

@papb I was taking a look in this feature and should we create another method or can we let findByPk receive more than one parameter??

@papb papb added the good first issue For issues. An issue that is a good choice for first-time contributors. label Aug 21, 2019
@papb
Copy link
Member

papb commented Aug 21, 2019

@fboechats Hello. I think it's better to create a new method, model.findByPks(). Would you like to take this?

@papb papb removed their assignment Aug 21, 2019
@fboechats
Copy link

@papb Sure, I will try to make a PR with this feature

@fboechats
Copy link

@papb Can I get some help on how to debug the method a created?? Tried using the vscode debug tool, but didn't work as expected.

@papb
Copy link
Member

papb commented Aug 23, 2019

@fboechats It usually works for me, I place some breakpoints and navigate through it. Can you be more specific?

@fboechats
Copy link

fboechats commented Aug 23, 2019

@papb Sure, it got some errors. I guess it's because I'm running mysql on docker. So now I'm trying to use Mocha tests to kind of debug.

@papb
Copy link
Member

papb commented Aug 23, 2019

@fboechats To work on this feature, which is not dialect-specific, I think you should just use sqlite instead, it is so much easier...

const { Sequelize } = require("sequelize");
const sequelize = new Sequelize("sqlite::memory:");

// do your work

@fboechats
Copy link

@papb I opened a PR with some initial idea and simple tests.

@papb papb added status: wip For issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started. and removed status: understood For issues. Applied when the issue is understood / reproducible. labels Aug 23, 2019
@netochaves
Copy link

@papb Can I get some help on how to debug the method a created?? Tried using the vscode debug tool, but didn't work as expected.

Hi @fboechats if you're still trying to debug the test, you can do it with inspect-brk flag, and use debugger to create a breakpoint.

@sushantdhiman sushantdhiman removed the status: wip For issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started. label May 3, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 8, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
@tapiwakundi
Copy link

@ustun @papb This issue is still open and I'm looking for a first issue to contribute. Is this still something we want to work on?

@ephys
Copy link
Member

ephys commented Jun 22, 2023

@tapiwakundi Sure! Feel free to give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
existing workaround For issues. There is a known workaround for this issue. good first issue For issues. An issue that is a good choice for first-time contributors. type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants