diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 17:37:36 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 17:37:36 +0530 |
commit | a3f3fab7955a0874bd58d1d997e344bdde710628 (patch) | |
tree | b7698ba14ef293b4756aef40d47edae8cd8e2416 | |
parent | 6f5e3a04d655e09c0a9a32fc94c752f84c7011f6 (diff) | |
download | rails-a3f3fab7955a0874bd58d1d997e344bdde710628.tar.gz rails-a3f3fab7955a0874bd58d1d997e344bdde710628.tar.bz2 rails-a3f3fab7955a0874bd58d1d997e344bdde710628.zip |
Add relation.from as a temporary workaround until arel relation has .from option
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 302c9fb724..c0b8e7e14f 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1632,7 +1632,8 @@ module ActiveRecord #:nodoc: group(construct_group(options[:group], options[:having], scope)). order(construct_order(options[:order], scope)). limit(construct_limit(options[:limit], scope)). - offset(construct_offset(options[:offset], scope)) + offset(construct_offset(options[:offset], scope)). + from(options[:from]) relation = relation.readonly if options[:readonly] diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index f1d1fa0790..87f6aa3643 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -28,6 +28,14 @@ module ActiveRecord create_new_relation(@relation.project(selects)) end + # TODO : This is temporary. We need .from in Arel. + attr_writer :from + def from(from) + relation = create_new_relation + relation.from = from + relation + end + def group(groups) create_new_relation(@relation.group(groups)) end @@ -94,7 +102,7 @@ module ActiveRecord :conditions => where_clause, :limit => @relation.taken, :offset => @relation.skipped, - :from => @relation.send(:table_sql, Arel::Sql::TableReference.new(@relation)) + :from => @from }, ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, @eager_load_associations, nil)) end @@ -242,8 +250,10 @@ module ActiveRecord end end - def create_new_relation(relation, readonly = @readonly, preload = @associations_to_preload, eager_load = @eager_load_associations) - Relation.new(@klass, relation, readonly, preload, eager_load) + 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 end def where_clause(join_string = "\n\tAND ") |