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 ] }
|
||||
end
|
||||
else
|
||||
b2 = SmqlToAR::And.new builder
|
||||
values.keys.each do |vid|
|
||||
builder.where @cols.collect {|col|
|
||||
b2.where SmqlToAR::Or[ *@cols.collect {|col|
|
||||
col.joins builder, table
|
||||
col = builder.column table+col.path, col.col
|
||||
self.class::Where % [ col, vid.to_s ]
|
||||
}
|
||||
}]
|
||||
end
|
||||
end
|
||||
self
|
||||
|
@ -272,7 +273,7 @@ class SmqlToAR
|
|||
def initialize model, cols, val
|
||||
super model, cols, val[1]
|
||||
# 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
|
||||
|
||||
def verify_column col
|
||||
|
@ -283,6 +284,7 @@ class SmqlToAR
|
|||
@cols.each do |col, sub|
|
||||
t = table+col.to_a
|
||||
builder.sub_joins t, col, *sub[0..1]
|
||||
#ap sub: sub[2..-1]
|
||||
sub[2..-1].each &it.build( builder, t)
|
||||
end
|
||||
self
|
||||
|
@ -386,7 +388,7 @@ class SmqlToAR
|
|||
|
||||
def build builder, table
|
||||
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
||||
builder.limit @args
|
||||
builder.limit = Array.wrap(@args).first.to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -396,7 +398,7 @@ class SmqlToAR
|
|||
|
||||
def build builder, table
|
||||
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
||||
builder.offset @args
|
||||
builder.offset = Array.wrap(@args).first.to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class SmqlToAR
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def sub_joins table, col, model, query
|
||||
|
@ -226,18 +226,21 @@ class SmqlToAR
|
|||
end
|
||||
def default() SmqlToAR::And 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
|
||||
|
||||
class And < SubBuilder
|
||||
def default; SmqlToAR::Or; end
|
||||
def build_where
|
||||
join ' AND '
|
||||
collect_build_where.join ' AND '
|
||||
end
|
||||
end
|
||||
|
||||
class Or < SubBuilder
|
||||
def build_where
|
||||
join ' OR '
|
||||
collect_build_where.join ' OR '
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue