adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.09k stars 195 forks source link

feat(base_model): add findManyBy method #1010

Closed RomainLanz closed 8 months ago

RomainLanz commented 8 months ago

Hey there! 👋🏻

This PR adds a findManyBy method to the ORM. Since we already have helpful static methods for most use cases, we were missing one that could fetch multiple records with a condition.

The method findManyBy can be used in two ways:

// Using an object 
User.findManyBy({ status: 'active'})

// Using two arguments
User.findManyBy('status', 'active')

If this PR is accepted, I will create another one to add the object syntax override to the findBy method.

thetutlage commented 8 months ago

Looks fine to me. Let's open another PR for the docs as well and then we can merge it.

RomainLanz commented 8 months ago

Should be good!

RomainLanz commented 8 months ago

About the lint issue, Prettier formatted it like that when saving. Also, neither npm run lint -- --fix or npm run format changed the format again. So probably a CI issue.

Julien-R44 commented 8 months ago

( fixed the lint issue with npm run lint -- --fix. probably an issue with your setup 👮 )

avonian commented 8 months ago

it's worth pointing out that while findByMany supports a clause, findBy only supports key/value, if its not a terrible ask it would be nice to update findBy as well so that it can also do clauses... this way it's more useful, as well as consistent :)

RomainLanz commented 8 months ago

Yes, as said in the last sentence, it is going to be added too!

avonian commented 8 months ago

oh whoops my mistake, i dont know how i missed that, sorry! 😅