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 /activerecord/lib/active_record/relation.rb | |
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
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 16 |
1 files changed, 13 insertions, 3 deletions
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 ") |