Class: Squeel::Nodes::Join
- Inherits:
-
Object
- Object
- Squeel::Nodes::Join
- Defined in:
- lib/squeel/nodes/join.rb
Overview
A node representing a joined association
Instance Attribute Summary collapse
-
#_join ⇒ Object
readonly
Returns the value of attribute _join.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compare with other objects.
-
#hash ⇒ Object
Implemented for equality testing.
-
#initialize(name, type = Arel::InnerJoin, klass = nil) ⇒ Join
constructor
Create a new Join node.
-
#inner ⇒ Join
Set the join type to an inner join.
-
#method_missing(method_id, *args) ⇒ Object
Ensures that a Join can be used as the base of a new KeyPath.
-
#outer ⇒ Join
Set the join type to an outer join.
- #polymorphic? ⇒ Boolean
-
#to_sym ⇒ NilClass
expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.
-
#~ ⇒ KeyPath
Return a KeyPath containing only this Join, but flagged as absolute.
Constructor Details
#initialize(name, type = Arel::InnerJoin, klass = nil) ⇒ Join
Create a new Join node
15 16 17 |
# File 'lib/squeel/nodes/join.rb', line 15 def initialize(name, type = Arel::InnerJoin, klass = nil) @_join = Polyamorous::Join.new(name, type, klass) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#node_name ⇒ KeyPath #node_name(klass) ⇒ KeyPath
Ensures that a Join can be used as the base of a new KeyPath
59 60 61 62 63 64 65 66 |
# File 'lib/squeel/nodes/join.rb', line 59 def method_missing(method_id, *args) super if method_id == :to_ary if (args.size == 1) && (Class === args[0]) KeyPath.new(self, Join.new(method_id, Arel::InnerJoin, args[0])) else KeyPath.new(self, method_id) end end |
Instance Attribute Details
#_join ⇒ Object (readonly)
Returns the value of attribute _join.
7 8 9 |
# File 'lib/squeel/nodes/join.rb', line 7 def _join @_join end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Compare with other objects
43 44 45 46 47 48 |
# File 'lib/squeel/nodes/join.rb', line 43 def eql?(other) self.class.eql?(other.class) && self._name.eql?(other._name) && self._type.eql?(other._type) && self._klass.eql?(other._klass) end |
#hash ⇒ Object
Implemented for equality testing
38 39 40 |
# File 'lib/squeel/nodes/join.rb', line 38 def hash [_name, _type, _klass].hash end |
#inner ⇒ Join
Set the join type to an inner join
21 22 23 24 |
# File 'lib/squeel/nodes/join.rb', line 21 def inner self._type = Arel::InnerJoin self end |
#outer ⇒ Join
Set the join type to an outer join
28 29 30 31 |
# File 'lib/squeel/nodes/join.rb', line 28 def outer self._type = Arel::OuterJoin self end |
#polymorphic? ⇒ Boolean
33 34 35 |
# File 'lib/squeel/nodes/join.rb', line 33 def polymorphic? _klass end |
#to_sym ⇒ NilClass
expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.
80 81 82 |
# File 'lib/squeel/nodes/join.rb', line 80 def to_sym nil end |
#~ ⇒ KeyPath
Return a KeyPath containing only this Join, but flagged as absolute. This helps Joins behave more like a KeyPath, as anyone using the Squeel DSL is likely to think of them as such.
72 73 74 |
# File 'lib/squeel/nodes/join.rb', line 72 def ~ KeyPath.new [], self, true end |