fixes: OR...
This commit is contained in:
parent
09dfa782a8
commit
863ebca9cd
|
@ -159,12 +159,13 @@ class SmqlToAR
|
||||||
builder.where values.keys.collect {|vid| self.class::Where % [ col, vid.to_s ] }
|
builder.where values.keys.collect {|vid| self.class::Where % [ col, vid.to_s ] }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
b2 = SmqlToAR::And.new builder
|
||||||
values.keys.each do |vid|
|
values.keys.each do |vid|
|
||||||
builder.where @cols.collect {|col|
|
b2.where SmqlToAR::Or[ *@cols.collect {|col|
|
||||||
col.joins builder, table
|
col.joins builder, table
|
||||||
col = builder.column table+col.path, col.col
|
col = builder.column table+col.path, col.col
|
||||||
self.class::Where % [ col, vid.to_s ]
|
self.class::Where % [ col, vid.to_s ]
|
||||||
}
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
|
@ -272,7 +273,7 @@ class SmqlToAR
|
||||||
def initialize model, cols, val
|
def initialize model, cols, val
|
||||||
super model, cols, val[1]
|
super model, cols, val[1]
|
||||||
# sub: model, subquery, sub(condition)
|
# sub: model, subquery, sub(condition)
|
||||||
@cols.each {|col, sub| sub[ 1...1] = SmqlToAR.new( col.relation, val[0]).parse }
|
@cols.each {|col, sub| sub[ 1..-1] = SmqlToAR.new( col.relation, val[0]).parse, *sub[-1] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_column col
|
def verify_column col
|
||||||
|
@ -283,6 +284,7 @@ class SmqlToAR
|
||||||
@cols.each do |col, sub|
|
@cols.each do |col, sub|
|
||||||
t = table+col.to_a
|
t = table+col.to_a
|
||||||
builder.sub_joins t, col, *sub[0..1]
|
builder.sub_joins t, col, *sub[0..1]
|
||||||
|
#ap sub: sub[2..-1]
|
||||||
sub[2..-1].each &it.build( builder, t)
|
sub[2..-1].each &it.build( builder, t)
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
|
@ -386,7 +388,7 @@ class SmqlToAR
|
||||||
|
|
||||||
def build builder, table
|
def build builder, table
|
||||||
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
||||||
builder.limit @args
|
builder.limit = Array.wrap(@args).first.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -396,7 +398,7 @@ class SmqlToAR
|
||||||
|
|
||||||
def build builder, table
|
def build builder, table
|
||||||
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
||||||
builder.offset @args
|
builder.offset = Array.wrap(@args).first.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_join orig, pretable, table, prekey, key
|
def build_join orig, pretable, table, prekey, key
|
||||||
" LEFT OUTER JOIN #{orig} AS #{quote_table_name table} ON #{column pretable, prekey} = #{column table, key} "
|
" LEFT JOIN #{orig} AS #{quote_table_name table} ON #{column pretable, prekey} = #{column table, key} "
|
||||||
end
|
end
|
||||||
|
|
||||||
def sub_joins table, col, model, query
|
def sub_joins table, col, model, query
|
||||||
|
@ -226,18 +226,21 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
def default() SmqlToAR::And end
|
def default() SmqlToAR::And end
|
||||||
def default_new( parent) default.new self, parent, false end
|
def default_new( parent) default.new self, parent, false end
|
||||||
|
def collect_build_where
|
||||||
|
collect {|x| x.respond_to?( :build_where) ? x.build_where : x.to_s }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class And < SubBuilder
|
class And < SubBuilder
|
||||||
def default; SmqlToAR::Or; end
|
def default; SmqlToAR::Or; end
|
||||||
def build_where
|
def build_where
|
||||||
join ' AND '
|
collect_build_where.join ' AND '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Or < SubBuilder
|
class Or < SubBuilder
|
||||||
def build_where
|
def build_where
|
||||||
join ' OR '
|
collect_build_where.join ' OR '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue