Module: ROM::SQL::Plugin::AssocMacros
- Defined in:
- lib/rom/sql/plugin/assoc_macros.rb,
lib/rom/sql/plugin/assoc_macros/class_interface.rb
Defined Under Namespace
Modules: ClassInterface
Class Method Summary collapse
-
.included(relation) ⇒ Object
private
Extends a relation class with assoc-macros and instance-level methods.
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
- #model ⇒ Object private
Class Method Details
.included(relation) ⇒ 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.
Extends a relation class with assoc-macros and instance-level methods
10 11 12 13 |
# File 'lib/rom/sql/plugin/assoc_macros.rb', line 10 def self.included(relation) super relation.extend(ClassInterface) end |
Instance Method Details
#association_join(name, options = {}) ⇒ Object
Join configured association.
Uses INNER JOIN type.
37 38 39 |
# File 'lib/rom/sql/plugin/assoc_macros.rb', line 37 def association_join(name, = {}) graph_join(name, :inner, ) end |
#association_left_join(name, options = {}) ⇒ Object
Join configured association
Uses LEFT JOIN type.
58 59 60 |
# File 'lib/rom/sql/plugin/assoc_macros.rb', line 58 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.
89 90 91 |
# File 'lib/rom/sql/plugin/assoc_macros.rb', line 89 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rom/sql/plugin/assoc_macros.rb', line 63 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.relation.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 |
#model ⇒ 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.
16 17 18 |
# File 'lib/rom/sql/plugin/assoc_macros.rb', line 16 def model self.class.model end |