mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Use conditionals and implicit returns rather than explicit returns and postfix ifs (it's easier to read)
This commit is contained in:
@@ -21,9 +21,13 @@ module ActiveRecord
|
||||
# have a size larger than zero, and you need to fetch that collection afterwards, it'll take one fewer
|
||||
# SELECT query if you use #length.
|
||||
def size
|
||||
return @owner.send(:read_attribute, cached_counter_attribute_name) if has_cached_counter?
|
||||
return @target.size if loaded?
|
||||
return count
|
||||
if has_cached_counter?
|
||||
@owner.send(:read_attribute, cached_counter_attribute_name)
|
||||
elsif loaded?
|
||||
@target.size
|
||||
else
|
||||
count
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
Reference in New Issue
Block a user