has_one-reflection (like has_many), group & having. subqueries deactivated
This commit is contained in:
parent
d5aa6052ec
commit
f3bcdd4b25
|
@ -101,12 +101,6 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class UnknownHavingMethod < SMQLError
|
|
||||||
def initialize expected, got
|
|
||||||
super :expected => expected, :got => got
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class BuilderError < Exception; end
|
class BuilderError < Exception; end
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
|
@ -248,7 +248,7 @@ class SmqlToAR
|
||||||
col.joins.each {|j, m| builder.joins table+j, m }
|
col.joins.each {|j, m| builder.joins table+j, m }
|
||||||
builder.joins t, model
|
builder.joins t, model
|
||||||
b2 = 1 == sub.length ? builder : Or.new( builder)
|
b2 = 1 == sub.length ? builder : Or.new( builder)
|
||||||
sub.each {|i| i.collect( &it.build( And.new( b2), t)) }
|
sub.each {|i| i.collect( &it.build( And.new( b2), t)); p 'or' => b2 }
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
@ -266,6 +266,7 @@ class SmqlToAR
|
||||||
# is, second is not allowed (limit and order must be in root) and this means something like
|
# is, second is not allowed (limit and order must be in root) and this means something like
|
||||||
# "Person must have the Article owned by Person which has 'some text' in content.
|
# "Person must have the Article owned by Person which has 'some text' in content.
|
||||||
# limit and order has no function in this query and this article needn't to be the last."
|
# limit and order has no function in this query and this article needn't to be the last."
|
||||||
|
=begin
|
||||||
class SubEqualJoin < EqualJoin
|
class SubEqualJoin < EqualJoin
|
||||||
Operator = '()'
|
Operator = '()'
|
||||||
Expected = [lambda {|x| x.kind_of?( Array) and (1..2).include?( x.length) and x.all?( &it.kind_of?( Hash))}]
|
Expected = [lambda {|x| x.kind_of?( Array) and (1..2).include?( x.length) and x.all?( &it.kind_of?( Hash))}]
|
||||||
|
@ -290,6 +291,7 @@ class SmqlToAR
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
Equal = simple_condition Condition, '=', "%s = %s", [Array, String, Numeric]
|
Equal = simple_condition Condition, '=', "%s = %s", [Array, String, Numeric]
|
||||||
Equal2 = simple_condition Equal, '', "%s = %s", [String, Numeric]
|
Equal2 = simple_condition Equal, '', "%s = %s", [String, Numeric]
|
||||||
|
@ -297,8 +299,8 @@ class SmqlToAR
|
||||||
LesserThan = simple_condition Condition, '<', "%s < %s", [Array, Numeric]
|
LesserThan = simple_condition Condition, '<', "%s < %s", [Array, Numeric]
|
||||||
NotIlike = simple_condition Condition, '!~', "%s NOT ILIKE %s", [Array, String]
|
NotIlike = simple_condition Condition, '!~', "%s NOT ILIKE %s", [Array, String]
|
||||||
Ilike = simple_condition Condition, '~', "%s ILIKE %s", [Array, String]
|
Ilike = simple_condition Condition, '~', "%s ILIKE %s", [Array, String]
|
||||||
Exists = simple_condition Condition, '', '%s IS NOT NULL', [true]
|
Exists = simple_condition Condition, '', '%s IS NOT NULL', [TrueClass]
|
||||||
NotExists = simple_condition Condition, '', '%s IS NULL', [false]
|
NotExists = simple_condition Condition, '', '%s IS NULL', [FalseClass]
|
||||||
|
|
||||||
Join = simple_condition EqualJoin, '', nil, [Hash]
|
Join = simple_condition EqualJoin, '', nil, [Hash]
|
||||||
InRange2 = simple_condition InRange, '', nil, [Range]
|
InRange2 = simple_condition InRange, '', nil, [Range]
|
||||||
|
@ -382,63 +384,6 @@ class SmqlToAR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class GroupBy < Function
|
|
||||||
Name = :group
|
|
||||||
Excepted = [String, Array]
|
|
||||||
|
|
||||||
def initialize model, func, args
|
|
||||||
super model, func, args.collect( &Columnt.method( :new))
|
|
||||||
end
|
|
||||||
|
|
||||||
def build builder, table
|
|
||||||
return if @args.blank?
|
|
||||||
@args.each do |col|
|
|
||||||
t = Column.new *(table + col.to_a)
|
|
||||||
raise_unless 1 == t.length, RootOnlyFunctionError.new( t)
|
|
||||||
builder.group t
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Having < Function
|
|
||||||
Name = :having
|
|
||||||
Excepted = [Array]
|
|
||||||
|
|
||||||
def initialize model, func, args
|
|
||||||
args = Hash[ *args.collect do |col, meth|
|
|
||||||
col = Column.new col
|
|
||||||
case meth.to_sym
|
|
||||||
when :max, :min
|
|
||||||
else raise UnknownHavingMethod.new( [:max, :min], meth)
|
|
||||||
end
|
|
||||||
[col, meth]
|
|
||||||
end]
|
|
||||||
super model, func, args
|
|
||||||
end
|
|
||||||
|
|
||||||
def build builder, table
|
|
||||||
return if @args.blank?
|
|
||||||
@args.each do |col, meth|
|
|
||||||
t = Column.new *(table + col.to_a)
|
|
||||||
raise_unless 1 == t.length, RootOnlyFunctionError.new( t)
|
|
||||||
builder.having meth => t
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Max < Having
|
|
||||||
Name = :max
|
|
||||||
Expected = [String]
|
|
||||||
|
|
||||||
def initialize model, func, args
|
|
||||||
super model, :having, Hash[ *args.collect {|col| [col, func] } ]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Min < Max
|
|
||||||
Name = :min
|
|
||||||
end
|
|
||||||
|
|
||||||
class Limit < Function
|
class Limit < Function
|
||||||
Name = :limit
|
Name = :limit
|
||||||
Expected = [Fixnum]
|
Expected = [Fixnum]
|
||||||
|
|
|
@ -43,7 +43,6 @@ class SmqlToAR
|
||||||
@table_alias[ @base_table] = @base_table.first
|
@table_alias[ @base_table] = @base_table.first
|
||||||
t = quote_table_name @table_alias[ @base_table]
|
t = quote_table_name @table_alias[ @base_table]
|
||||||
@_select, @_joins, @_joined, @_includes, @_order = ["DISTINCT #{t}.*"], "", [@base_table], [], []
|
@_select, @_joins, @_joined, @_includes, @_order = ["DISTINCT #{t}.*"], "", [@base_table], [], []
|
||||||
@_group, @_having = {}, {}
|
|
||||||
@table_model = {@base_table => @model}
|
@table_model = {@base_table => @model}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,14 +66,6 @@ class SmqlToAR
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def group col
|
|
||||||
@_group.push col
|
|
||||||
end
|
|
||||||
|
|
||||||
def having h
|
|
||||||
@_having.update h
|
|
||||||
end
|
|
||||||
|
|
||||||
def quote_column_name name
|
def quote_column_name name
|
||||||
@quoter.quote_column_name( name).gsub /"\."/, ','
|
@quoter.quote_column_name( name).gsub /"\."/, ','
|
||||||
end
|
end
|
||||||
|
@ -114,7 +105,7 @@ class SmqlToAR
|
||||||
join_ srctable, refl.klass, query, throughtable
|
join_ srctable, refl.klass, query, throughtable
|
||||||
when ActiveRecord::Reflection::AssociationReflection
|
when ActiveRecord::Reflection::AssociationReflection
|
||||||
case refl.macro
|
case refl.macro
|
||||||
when :has_many
|
when :has_many, :has_one
|
||||||
@_joins += build_join query, pretable, t, premodel.primary_key, refl.primary_key_name
|
@_joins += build_join query, pretable, t, premodel.primary_key, refl.primary_key_name
|
||||||
when :belongs_to
|
when :belongs_to
|
||||||
@_joins += build_join query, pretable, t, refl.primary_key_name, premodel.primary_key
|
@_joins += build_join query, pretable, t, refl.primary_key_name, premodel.primary_key
|
||||||
|
|
Loading…
Reference in a new issue