提交 a76ebe50 编写于 作者: R Ryuta Kamizono

Remove unnecessary `set_inverse_instance` in finder methods

Because `scope` (`target_scope`) is a `AssociationRelation`.
`AssociationRelation` handles `set_inverse_instance`.

https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/association_relation.rb#L31-L33
上级 c205e3fc
......@@ -152,9 +152,7 @@ def take(n = nil)
if loaded?
n ? target.take(n) : target.first
else
scope.take(n).tap do |record|
set_inverse_instance record if record.is_a? ActiveRecord::Base
end
scope.take(n)
end
end
......@@ -656,9 +654,7 @@ def first_nth_or_last(type, *args)
args.shift if args.first.is_a?(Hash) && args.first.empty?
collection = fetch_first_nth_or_last_using_find?(args) ? scope : load_target
collection.send(type, *args).tap do |record|
set_inverse_instance record if record.is_a? ActiveRecord::Base
end
collection.send(type, *args)
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册