Class: SmqlToAR::ConditionTypes::EqualJoin

Inherits:
Condition
  • Object
show all
Defined in:
lib/smql_to_ar/condition_types.rb

Overview

Examples: { ‘articles=>’ => { id: 1 } } { ‘articles=>’ => [ { id: 1 }, { id: 2 } ] }

Constant Summary collapse

Operator =
'=>'
Expected =
[Hash, lambda {|x| x.kind_of?( Array) and x.all? {|y| y.kind_of?( Hash) }}]

Constants inherited from Condition

Condition::Where

Instance Attribute Summary

Attributes inherited from Condition

#cols, #value

Instance Method Summary collapse

Methods inherited from Condition

#condition_build, inspect, #inspect, try_parse, #verify, #verify_allowed

Methods included from Assertion

#raise_if, #raise_unless

Constructor Details

#initialize(*pars) ⇒ EqualJoin

Returns a new instance of EqualJoin.



284
285
286
287
288
289
290
291
292
293
# File 'lib/smql_to_ar/condition_types.rb', line 284

def initialize *pars
	super( *pars)
	@value = Array.wrap @value
	cols = {}
	@cols.each do |col|
		col_model = col.relation
		cols[col] = [col_model] + @value.collect {|val| ConditionTypes.try_parse( col_model, val) }
	end
	@cols = cols
end

Instance Method Details

#equal_join_build(builder, table) ⇒ Object Also known as: build



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/smql_to_ar/condition_types.rb', line 299

def equal_join_build builder, table
	if 2 < @cols.first.second.length
		b2, b3 = And, Or
	else
		b2, b3 = Or, And
	end
	b2 = b2.new builder
	@cols.each do |col, sub|
		model, *sub = sub
		t = table + col.path + [col.col]
		col.joins builder, table
		builder.joins t, model
		b4 = b3.new( b2)
		sub.each do |i|
			b5 = And.new b4
			i.collect {|j| j.build b5, t }
		end
	end
	self
end

#verify_column(col) ⇒ Object



295
296
297
# File 'lib/smql_to_ar/condition_types.rb', line 295

def verify_column col
	raise_unless col.relation, NonExistingRelationError.new( %w[Relation], col)
end