Module: ROM::SQL::Relation::Associations
- Included in:
- ROM::SQL::Relation
- Defined in:
- lib/rom/sql/relation/associations.rb
Instance Method Summary collapse
-
#association_join(name, options = {}) ⇒ Object
Join configured association.
-
#association_left_join(name, options = {}) ⇒ Object
Join configured association.
- #graph(*args) ⇒ Object private
- #graph_join(assoc_name, join_type, options = {}) ⇒ Object private
Instance Method Details
#association_join(name, options = {}) ⇒ Object
Join configured association.
Uses INNER JOIN type.
22 23 24 |
# File 'lib/rom/sql/relation/associations.rb', line 22 def association_join(name, = {}) graph_join(name, :inner, ) end |
#association_left_join(name, options = {}) ⇒ Object
Join configured association
Uses LEFT JOIN type.
43 44 45 |
# File 'lib/rom/sql/relation/associations.rb', line 43 def association_left_join(name, = {}) graph_join(name, :left_outer, ) end |
#graph(*args) ⇒ 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.
74 75 76 |
# File 'lib/rom/sql/relation/associations.rb', line 74 def graph(*args) __new__(dataset.__send__(__method__, *args)) end |
#graph_join(assoc_name, join_type, options = {}) ⇒ 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rom/sql/relation/associations.rb', line 48 def graph_join(assoc_name, join_type, = {}) assoc = model.association_reflection(assoc_name) if assoc.nil? raise NoAssociationError, "Association #{assoc_name.inspect} has not been " \ "defined for relation #{name.inspect}" end type = assoc[:type] table_name = assoc[:class].table_name graph_rel = if type == :many_to_many select = [:select] || {} graph_join_many_to_many(table_name, assoc, select) else graph_join_other(table_name, assoc, type, join_type, ) end graph_rel = graph_rel.where(assoc[:conditions]) if assoc[:conditions] graph_rel end |