aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-07-31 16:08:22 -0300
committerEmilio Tagua <miloops@gmail.com>2009-07-31 16:08:22 -0300
commitc1cbf02e3170f1004daf4a146cbc41176c2458d3 (patch)
tree80fab7d4fd73ddd1873ade3d01df5c9ad526747f /activerecord/lib
parentca1e62f14219da3990bb354d4a363dbe6fa13435 (diff)
downloadrails-c1cbf02e3170f1004daf4a146cbc41176c2458d3.tar.gz
rails-c1cbf02e3170f1004daf4a146cbc41176c2458d3.tar.bz2
rails-c1cbf02e3170f1004daf4a146cbc41176c2458d3.zip
Added ActiveRecord::Relation tests. Allow Relation to accept conditional
hashes and arrays like #find does.
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rw-r--r--activerecord/lib/active_record/relation.rb15
2 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 7a34e345a2..9a3a02870a 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -663,7 +663,11 @@ module ActiveRecord #:nodoc:
# This is an alias for find(:all). You can pass in all the same arguments to this method as you can
# to find(:all)
def all(*args)
- construct_finder_arel(*args)
+ if args.empty? && !scoped?(:find)
+ arel_table
+ else
+ construct_finder_arel(*args)
+ end
end
# Executes a custom SQL query against your database and returns all the results. The results will
@@ -2992,7 +2996,7 @@ module ActiveRecord #:nodoc:
end
def arel_table(reload = nil)
- @arel_table = Relation.new(self, self.class.table_name) if reload || @arel_table.nil?
+ @arel_table = Relation.new(self.class, self.class.table_name) if reload || @arel_table.nil?
@arel_table
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 36e8d98298..1c3a1dc53b 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -1,7 +1,7 @@
module ActiveRecord
class Relation
delegate :delete, :to_sql, :to => :relation
- CLAUSES_METHODS = ["where", "join", "project", "group", "order", "take", "skip"].freeze
+ CLAUSES_METHODS = ["project", "group", "order", "take", "skip"].freeze
attr_reader :relation, :klass
def initialize(klass, table = nil)
@@ -27,6 +27,19 @@ module ActiveRecord
}
end
+ def join(joins)
+ @relation = @relation.join(@klass.send(:construct_join, joins, nil)) if !joins.blank?
+ self
+ end
+
+ def where(conditions)
+ if !conditions.blank?
+ conditions = @klass.send(:merge_conditions, conditions) if [String, Hash, Array].include?(conditions.class)
+ @relation = @relation.where(conditions)
+ end
+ self
+ end
+
private
def method_missing(method, *args, &block)
if @relation.respond_to?(method)