diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-28 03:19:31 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-28 03:19:31 +0530 |
commit | e9e20ab6013424c098c88d357d210068a32a1b39 (patch) | |
tree | 5200e481ecdf16d92e59207b1f65c625f638a28d /activerecord/lib/active_record/relation.rb | |
parent | 630dc5073075ba73251400400caae802f8d97d41 (diff) | |
download | rails-e9e20ab6013424c098c88d357d210068a32a1b39.tar.gz rails-e9e20ab6013424c098c88d357d210068a32a1b39.tar.bz2 rails-e9e20ab6013424c098c88d357d210068a32a1b39.zip |
Use arel#from instead of the current hack
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index d0f6c5a63f..a789337027 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -21,7 +21,8 @@ module ActiveRecord 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 @@ module ActiveRecord 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 @@ module ActiveRecord :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 @@ module ActiveRecord 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 ") |