mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Rewrite Relation#readonly, eager_load, preload using Object#tap
This commit is contained in:
parent
1785e1b26e
commit
0a1ff1a14f
1 changed files with 4 additions and 12 deletions
|
@ -33,21 +33,15 @@ module ActiveRecord
|
||||||
alias :& :merge
|
alias :& :merge
|
||||||
|
|
||||||
def preload(*associations)
|
def preload(*associations)
|
||||||
relation = spawn
|
spawn.tap {|r| r.preload_associations += Array.wrap(associations) }
|
||||||
relation.preload_associations += Array.wrap(associations)
|
|
||||||
relation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def eager_load(*associations)
|
def eager_load(*associations)
|
||||||
relation = spawn
|
spawn.tap {|r| r.eager_load_associations += Array.wrap(associations) }
|
||||||
relation.eager_load_associations += Array.wrap(associations)
|
|
||||||
relation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def readonly(status = true)
|
def readonly(status = true)
|
||||||
relation = spawn
|
spawn.tap {|r| r.readonly = status }
|
||||||
relation.readonly = status
|
|
||||||
relation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def select(selects)
|
def select(selects)
|
||||||
|
@ -135,9 +129,7 @@ module ActiveRecord
|
||||||
@relation.join(join, join_type)
|
@relation.join(join, join_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
relation = spawn(join_relation)
|
spawn(join_relation) { |r| r.readonly = true }
|
||||||
relation.readonly = true
|
|
||||||
relation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def where(*args)
|
def where(*args)
|
||||||
|
|
Loading…
Reference in a new issue