class BabySqueel::Nodes::Attribute
Public Class Methods
new(parent, name)
click to toggle source
Calls superclass method
# File lib/baby_squeel/nodes/attribute.rb, line 6 def initialize(parent, name) @parent = parent @name = name.to_s super(parent._table[@name]) end
Public Instance Methods
_arel()
click to toggle source
Calls superclass method
# File lib/baby_squeel/nodes/attribute.rb, line 28 def _arel if @parent.kind_of?(BabySqueel::Association) && !@parent.alias? @parent.find_alias[@name] else super end end
in(rel)
click to toggle source
Calls superclass method
# File lib/baby_squeel/nodes/attribute.rb, line 12 def in(rel) if rel.is_a? ::ActiveRecord::Relation Nodes.wrap ::Arel::Nodes::In.new(self, sanitize_relation(rel)) else super end end
not_in(rel)
click to toggle source
Calls superclass method
# File lib/baby_squeel/nodes/attribute.rb, line 20 def not_in(rel) if rel.is_a? ::ActiveRecord::Relation Nodes.wrap ::Arel::Nodes::NotIn.new(self, sanitize_relation(rel)) else super end end
Private Instance Methods
sanitize_relation(rel)
click to toggle source
NullRelation must be treated as a special case, because NullRelation#to_sql returns an empty string. As such, we need to convert the NullRelation to regular relation. Conveniently, this approach automatically adds a 1=0. I have literally no idea why, but I’ll take it.
# File lib/baby_squeel/nodes/attribute.rb, line 43 def sanitize_relation(rel) if ::ActiveRecord::VERSION::MAJOR < 7 && rel.kind_of?(::ActiveRecord::NullRelation) other = rel.spawn other.extending_values -= [::ActiveRecord::NullRelation] sanitize_relation rel.unscoped.merge(other) else Arel.sql rel.to_sql end end