Permalink
Browse files

Use arel#from instead of the current hack

  • Loading branch information...
1 parent 630dc50 commit e9e20ab6013424c098c88d357d210068a32a1b39 @lifo lifo committed Dec 27, 2009
Showing with 5 additions and 10 deletions.
  1. +5 −10 activerecord/lib/active_record/relation.rb
@@ -21,7 +21,8 @@ def merge(r)
offset(r.skipped).
select(r.send(:select_clauses).join(', ')).
eager_load(r.eager_load_associations).
- preload(r.associations_to_preload)
+ preload(r.associations_to_preload).
+ from(r.send(:sources).any? ? r.send(:from_clauses) : nil)
end
alias :& :merge
@@ -42,12 +43,8 @@ def select(selects)
selects.present? ? create_new_relation(@relation.project(selects)) : create_new_relation
end
- # TODO : This is temporary. We need .from in Arel.
- attr_writer :from
def from(from)
- relation = create_new_relation
- relation.from = from
- relation
+ from.present? ? create_new_relation(@relation.from(from)) : create_new_relation
end
def group(groups)
@@ -130,7 +127,7 @@ def to_a
:conditions => where_clause,
:limit => @relation.taken,
:offset => @relation.skipped,
- :from => @from
+ :from => (@relation.send(:from_clauses) if @relation.send(:sources).any?)
},
ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, @eager_load_associations, nil))
end
@@ -303,9 +300,7 @@ def find_some(ids)
end
def create_new_relation(relation = @relation, readonly = @readonly, preload = @associations_to_preload, eager_load = @eager_load_associations)
- r = self.class.new(@klass, relation, readonly, preload, eager_load)
- r.from = @from
- r
+ self.class.new(@klass, relation, readonly, preload, eager_load)
end
def where_clause(join_string = "\n\tAND ")

0 comments on commit e9e20ab

Please sign in to comment.