Module: ROM::Plugins::Relation::SQL::AutoCombine::InstanceInterface Private
- Defined in:
- lib/rom/plugins/relation/sql/auto_combine.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#for_combine(spec) ⇒ SQL::Relation
private
Default methods for fetching combined relation.
- #preload(spec, source) ⇒ Object private
Instance Method Details
#for_combine(spec) ⇒ SQL::Relation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Default methods for fetching combined relation
This method is used by default by ‘combine`
35 36 37 38 39 40 41 42 |
# File 'lib/rom/plugins/relation/sql/auto_combine.rb', line 35 def for_combine(spec) case spec when ROM::SQL::Association spec.call(__registry__, self).preload(spec) else preload(spec) end end |
#preload(spec, source) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rom/plugins/relation/sql/auto_combine.rb', line 45 def preload(spec, source) case spec when ROM::SQL::Association::ManyToOne pk = source.source[source.source.primary_key].qualified where(pk => source.pluck(pk.name)) when Hash, ROM::SQL::Association source_key, target_key = spec.is_a?(Hash) ? spec.flatten(1) : spec.join_keys(__registry__).flatten(1) target_pks = source.pluck(source_key.to_sym) target_pks.uniq! where(target_key => target_pks) end end |