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 first_or_create family of methods to Active Record #2757

Merged
merged 4 commits into from
Sep 8, 2011

Conversation

mejibyte
Copy link
Contributor

This pull request let's you write:

User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson", :hot => true)

Take a look at #2420 for the discussion about this.

Andrés Mejía and others added 2 commits August 30, 2011 16:33
…uild to Active Record.

This let's you write things like:

    User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson", :hot => true)

Related to rails#2420.
@jonleighton
Copy link
Member

Thanks, I will review this in due course but it might be a few days.


<sql>
SELECT * FROM clients WHERE (clients.first_name = 'Ryan') LIMIT 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poor Ryan :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha

@ghost ghost assigned jonleighton Aug 31, 2011
#
# Expects arguments in the same format as <tt>Base.create</tt>.
#
# ==== Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a first example with no arguments to first_or_create? (As I think this will be the most common usage.)

E.g.

User.where(:first_name => 'Scarlett').first_or_create
# => <User id: 1, first_name: 'Scarlett'>

Also, I would remove the examples of creating several users at the same time, as I think this is a kind of odd use case and only works because create happens to be implemented that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both things done in d03aff7.

Andrés Mejía added 2 commits September 6, 2011 02:02
…e and removing examples that create several users at the same time (this is confusing and not really helpful).
@mejibyte
Copy link
Contributor Author

mejibyte commented Sep 8, 2011

@jonleighton @tenderlove I know you are busy with lots of stuff but can you take a quick look at this pull request? I think there's not much left to do before merging.

jonleighton added a commit that referenced this pull request Sep 8, 2011
Add first_or_create family of methods to Active Record
@jonleighton jonleighton merged commit cbf1dc7 into rails:master Sep 8, 2011
@jonleighton
Copy link
Member

Merged, thanks!

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.

None yet

5 participants