aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation/relations
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-13 18:31:35 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-13 18:31:35 -0800
commitbc4f6b8a29fc96c05efe0304ce7fad075818d2a2 (patch)
tree75f1b67bddf5ce5e247f57c5f9d8f8bde05c1f51 /lib/active_relation/relations
parent2e63ac91302e2df397a286fdaf9cea51635071a6 (diff)
downloadrails-bc4f6b8a29fc96c05efe0304ce7fad075818d2a2.tar.gz
rails-bc4f6b8a29fc96c05efe0304ce7fad075818d2a2.tar.bz2
rails-bc4f6b8a29fc96c05efe0304ce7fad075818d2a2.zip
experimenting with strategy pattern rather than conditional; not as terse, nor transparent, but i still feel it's better
Diffstat (limited to 'lib/active_relation/relations')
-rw-r--r--lib/active_relation/relations/base.rb10
-rw-r--r--lib/active_relation/relations/deletion.rb2
-rw-r--r--lib/active_relation/relations/insertion.rb2
-rw-r--r--lib/active_relation/relations/join.rb2
4 files changed, 8 insertions, 8 deletions
diff --git a/lib/active_relation/relations/base.rb b/lib/active_relation/relations/base.rb
index 71d15f31f1..c464b6bc31 100644
--- a/lib/active_relation/relations/base.rb
+++ b/lib/active_relation/relations/base.rb
@@ -1,7 +1,7 @@
module ActiveRelation
module Relations
class Base
- include SqlBuilder
+ include Sql::Quoting
module Iteration
include Enumerable
@@ -78,12 +78,12 @@ module ActiveRelation
ActiveRecord::Base.connection
end
- def to_sql(options = {})
- sql = [
- "SELECT #{attributes.collect{ |a| a.to_sql(:use_alias => true) }.join(', ')}",
+ def to_sql(strategy = Sql::Select.new)
+ strategy.select [
+ "SELECT #{attributes.collect{ |a| a.to_sql(Sql::Projection.new) }.join(', ')}",
"FROM #{table_sql}",
(joins unless joins.blank?),
- ("WHERE #{selects.collect{|s| s.to_sql(:quote => false)}.join("\n\tAND ")}" unless selects.blank?),
+ ("WHERE #{selects.collect{|s| s.to_sql(Sql::Predicate.new)}.join("\n\tAND ")}" unless selects.blank?),
("ORDER BY #{orders.collect(&:to_sql)}" unless orders.blank?),
("LIMIT #{limit.to_sql}" unless limit.blank?),
("OFFSET #{offset.to_sql}" unless offset.blank?)
diff --git a/lib/active_relation/relations/deletion.rb b/lib/active_relation/relations/deletion.rb
index 0276dc1bc4..add6440c2a 100644
--- a/lib/active_relation/relations/deletion.rb
+++ b/lib/active_relation/relations/deletion.rb
@@ -5,7 +5,7 @@ module ActiveRelation
@relation = relation
end
- def to_sql(options = {})
+ def to_sql(strategy = nil)
[
"DELETE",
"FROM #{table_sql}",
diff --git a/lib/active_relation/relations/insertion.rb b/lib/active_relation/relations/insertion.rb
index 86581c23d7..c82513ce0f 100644
--- a/lib/active_relation/relations/insertion.rb
+++ b/lib/active_relation/relations/insertion.rb
@@ -7,7 +7,7 @@ module ActiveRelation
@relation, @record = relation, record
end
- def to_sql(options = {})
+ def to_sql(strategy = nil)
[
"INSERT",
"INTO #{table_sql}",
diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb
index 3d50365c40..4e6c85979e 100644
--- a/lib/active_relation/relations/join.rb
+++ b/lib/active_relation/relations/join.rb
@@ -38,7 +38,7 @@ module ActiveRelation
private
def join
- "#{join_sql} #{relation2.send(:table_sql)} ON #{predicates.collect { |p| p.to_sql(:quote => false) }.join(' AND ')}"
+ "#{join_sql} #{relation2.send(:table_sql)} ON #{predicates.collect { |p| p.to_sql(Sql::Predicate.new) }.join(' AND ')}"
end
end
end