has_one-reflection (like has_many), group & having. subqueries deactivated

This commit is contained in:
Denis Knauf 2011-10-25 16:31:18 +02:00
parent d5aa6052ec
commit f3bcdd4b25
3 changed files with 7 additions and 77 deletions

View file

@ -101,12 +101,6 @@ class SmqlToAR
end
end
class UnknownHavingMethod < SMQLError
def initialize expected, got
super :expected => expected, :got => got
end
end
class BuilderError < Exception; end
#############################################################################

View file

@ -248,7 +248,7 @@ class SmqlToAR
col.joins.each {|j, m| builder.joins table+j, m }
builder.joins t, model
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
self
end
@ -266,6 +266,7 @@ class SmqlToAR
# 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.
# limit and order has no function in this query and this article needn't to be the last."
=begin
class SubEqualJoin < EqualJoin
Operator = '()'
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
end
end
=end
Equal = simple_condition Condition, '=', "%s = %s", [Array, String, Numeric]
Equal2 = simple_condition Equal, '', "%s = %s", [String, Numeric]
@ -297,8 +299,8 @@ class SmqlToAR
LesserThan = simple_condition Condition, '<', "%s < %s", [Array, Numeric]
NotIlike = simple_condition Condition, '!~', "%s NOT ILIKE %s", [Array, String]
Ilike = simple_condition Condition, '~', "%s ILIKE %s", [Array, String]
Exists = simple_condition Condition, '', '%s IS NOT NULL', [true]
NotExists = simple_condition Condition, '', '%s IS NULL', [false]
Exists = simple_condition Condition, '', '%s IS NOT NULL', [TrueClass]
NotExists = simple_condition Condition, '', '%s IS NULL', [FalseClass]
Join = simple_condition EqualJoin, '', nil, [Hash]
InRange2 = simple_condition InRange, '', nil, [Range]
@ -382,63 +384,6 @@ class SmqlToAR
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
Name = :limit
Expected = [Fixnum]

View file

@ -43,7 +43,6 @@ class SmqlToAR
@table_alias[ @base_table] = @base_table.first
t = quote_table_name @table_alias[ @base_table]
@_select, @_joins, @_joined, @_includes, @_order = ["DISTINCT #{t}.*"], "", [@base_table], [], []
@_group, @_having = {}, {}
@table_model = {@base_table => @model}
end
@ -67,14 +66,6 @@ class SmqlToAR
self
end
def group col
@_group.push col
end
def having h
@_having.update h
end
def quote_column_name name
@quoter.quote_column_name( name).gsub /"\."/, ','
end
@ -114,7 +105,7 @@ class SmqlToAR
join_ srctable, refl.klass, query, throughtable
when ActiveRecord::Reflection::AssociationReflection
case refl.macro
when :has_many
when :has_many, :has_one
@_joins += build_join query, pretable, t, premodel.primary_key, refl.primary_key_name
when :belongs_to
@_joins += build_join query, pretable, t, refl.primary_key_name, premodel.primary_key