mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Using more precise method signatures for AR::Relation#first_or_create family of methods.
This commit is contained in:
@@ -118,22 +118,22 @@ module ActiveRecord
|
||||
# user.last_name = "O'Hara"
|
||||
# end
|
||||
# # => <User id: 2, first_name: 'Scarlett', last_name: 'Johansson'>
|
||||
def first_or_create(*args, &block)
|
||||
first || create(*args, &block)
|
||||
def first_or_create(attributes = nil, options = {}, &block)
|
||||
first || create(attributes, options, &block)
|
||||
end
|
||||
|
||||
# Like <tt>first_or_create</tt> but calls <tt>create!</tt> so an exception is raised if the created record is invalid.
|
||||
#
|
||||
# Expects arguments in the same format as <tt>Base.create!</tt>.
|
||||
def first_or_create!(*args, &block)
|
||||
first || create!(*args, &block)
|
||||
def first_or_create!(attributes = nil, options = {}, &block)
|
||||
first || create!(attributes, options, &block)
|
||||
end
|
||||
|
||||
# Like <tt>first_or_create</tt> but calls <tt>new</tt> instead of <tt>create</tt>.
|
||||
#
|
||||
# Expects arguments in the same format as <tt>Base.new</tt>.
|
||||
def first_or_new(*args, &block)
|
||||
first || new(*args, &block)
|
||||
def first_or_new(attributes = nil, options = {}, &block)
|
||||
first || new(attributes, options, &block)
|
||||
end
|
||||
alias :first_or_build :first_or_new
|
||||
|
||||
|
||||
Reference in New Issue
Block a user