提交 ca778584 编写于 作者: J Jon Leighton

Condense first_or_last a bit more

上级 fdee153f
......@@ -498,7 +498,7 @@ def ensure_owner_is_persisted!
# * target contains new or changed record(s)
# * the first arg is an integer (which indicates the number of records to be returned)
def fetch_first_or_last_using_find?(args)
if args.first.kind_of?(Hash) && !args.first.empty?
if args.first.is_a?(Hash)
true
else
!(loaded? ||
......@@ -536,12 +536,10 @@ def find_by_scan(*args)
# Fetches the first/last using SQL if possible, otherwise from the target array.
def first_or_last(type, *args)
if fetch_first_or_last_using_find?(args)
scoped.send(type, *args)
else
args.shift if args.first.kind_of?(Hash) && args.first.empty?
load_target.send(type, *args)
end
args.shift if args.first.is_a?(Hash) && args.first.empty?
collection = fetch_first_or_last_using_find?(args) ? scoped : load_target
collection.send(type, *args)
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册