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 optional block to associations find method #141

Merged

Conversation

barrerajl
Copy link
Contributor

  • Call class find if id is provided
  • Call find on find_some enumerable if block given
  • Else return find_some enumerable (same happens in ruby by default in an array)

- Call class find if param is provided
- Call find on find_some enumerable if block given
- Else return find_some enumerable (same happens in ruby by default in an array)
@balvig
Copy link
Owner

balvig commented Jun 5, 2023

Thank you for this @barrerajl!

It looks as if Rails supports the following as well:

User.find do |u|                       
  u.name == "Bob"
end                                    
#  User Load (17.0ms)  SELECT `users`.* FROM `users`
#  => <User:0x000000010713fbe8 id: 16, name: "Bob">

Maybe if we're going to be adding this feature, it would be good to get this working consistently here as well?
Have added a test case, in case you're able to take a look.

@barrerajl
Copy link
Contributor Author

Let me check. I can add some code for sure.

@barrerajl
Copy link
Contributor Author

@balvig This should do it!

🙇

@balvig
Copy link
Owner

balvig commented Jun 7, 2023

Thank you for this @barrerajl! 🙏
I made a few tweaks but looks good to go now.
Will merge and release a new version. 👍

@balvig balvig merged commit c3933f5 into balvig:main Jun 7, 2023
@barrerajl barrerajl deleted the barrerajl/add_block_to_associations_find branch June 7, 2023 06:25
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.

3 participants