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

Revise documentation example wording - ActiveRecord::Relation#find_or_create_by [ci skip] #42443

Merged

Conversation

daven97
Copy link
Contributor

@daven97 daven97 commented Jun 10, 2021

Summary

Updating the wording of the example to clarify the meaning and to match the wording of the previous paragraph.

Other Information

I know this is only one word, but I feel that this wording change is important as this confused me when I was reading the documentation for find_or_create_by for the first time. The word different used to describe this example implies either that there will be some sort of comparison to other users, or that the last name of the created record's last_name is different from the former version of the example, or that the last name used in this alternative example is different from the one used in its former counterpart, none of which are true.

In reality, the following is possible:

User.find_or_create_by({first_name: "Penélope", last_name: "Johansson"})
# => #<User id: 1, first_name: "Penélope", last_name: "Johansson">

User.find_or_create_by(first_name: 'Scarlett') do |user|
  user.last_name = 'Johansson'
end
# => #<User id: 2, first_name: "Scarlett", last_name: "Johansson">

User.all
# => #<ActiveRecord::Relation [<User id: 1, first_name: "Penélope", last_name: "Johansson">, <User id: 2, first_name: "Scarlett", last_name: "Johansson">]

I believe that this wording change more accurately and clearly reflects the actual functionality of find_or_create_by and would better aid others such as myself in reading the documentation going forward. I feel that using the wording from the previous example again here will improve the documentation for find_or_create_by.

@zzak zzak merged commit 4a85239 into rails:main Jun 10, 2021
@daven97 daven97 deleted the daven97update_active_record_relation_wording branch June 10, 2021 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants