Skip to content

Commit

Permalink
Stop supporting blank arguments to AR#relation query methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Dec 25, 2009
1 parent 95274b2 commit a73fa93
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions activerecord/lib/active_record/relation.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,56 +57,48 @@ def first
end end


def select(selects) def select(selects)
selects.blank? ? self : create_new_relation(@relation.project(selects)) create_new_relation(@relation.project(selects))
end end


def group(groups) def group(groups)
groups.blank? ? self : create_new_relation(@relation.group(groups)) create_new_relation(@relation.group(groups))
end end


def order(orders) def order(orders)
orders.blank? ? self : create_new_relation(@relation.order(orders)) create_new_relation(@relation.order(orders))
end end


def limit(limits) def limit(limits)
limits.blank? ? self : create_new_relation(@relation.take(limits)) create_new_relation(@relation.take(limits))
end end


def offset(offsets) def offset(offsets)
offsets.blank? ? self : create_new_relation(@relation.skip(offsets)) create_new_relation(@relation.skip(offsets))
end end


def on(join) def on(join)
join.blank? ? self : create_new_relation(@relation.on(join)) create_new_relation(@relation.on(join))
end end


def joins(join, join_type = nil) def joins(join, join_type = nil)
if join.blank? join = case join
self when String
else @relation.join(join)
join = case join when Hash, Array, Symbol
when String if @klass.send(:array_of_strings?, join)
@relation.join(join) @relation.join(join.join(' '))
when Hash, Array, Symbol
if @klass.send(:array_of_strings?, join)
@relation.join(join.join(' '))
else
@relation.join(@klass.send(:build_association_joins, join))
end
else else
@relation.join(join, join_type) @relation.join(@klass.send(:build_association_joins, join))
end end
create_new_relation(join) else
@relation.join(join, join_type)
end end
create_new_relation(join)
end end


def where(conditions) def where(conditions)
if conditions.blank? conditions = @klass.send(:merge_conditions, conditions) if [String, Hash, Array].include?(conditions.class)
self create_new_relation(@relation.where(conditions))
else
conditions = @klass.send(:merge_conditions, conditions) if [String, Hash, Array].include?(conditions.class)
create_new_relation(@relation.where(conditions))
end
end end


def respond_to?(method) def respond_to?(method)
Expand Down

0 comments on commit a73fa93

Please sign in to comment.