aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/relations/relation.rb6
-rw-r--r--lib/arel/relations/utilities/compound.rb4
-rw-r--r--spec/arel/unit/relations/alias_spec.rb8
3 files changed, 11 insertions, 7 deletions
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index 50110c7416..986bc3fbeb 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -4,6 +4,10 @@ module Arel
Session.new
end
+ def select_value
+ engine.select_value self.to_sql
+ end
+
def select_values
engine.select_values self.to_sql
end
@@ -19,8 +23,8 @@ module Arel
"FROM #{table_sql(Sql::TableReference.new(self))}",
(joins(self) unless joins(self).blank? ),
("WHERE #{wheres .collect { |w| w.to_sql(Sql::WhereClause.new(self)) }.join("\n\tAND ")}" unless wheres.blank? ),
- ("ORDER BY #{orders .collect { |o| o.to_sql(Sql::OrderClause.new(self)) }.join(', ')}" unless orders.blank? ),
("GROUP BY #{groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) }.join(', ')}" unless groupings.blank? ),
+ ("ORDER BY #{orders .collect { |o| o.to_sql(Sql::OrderClause.new(self)) }.join(', ')}" unless orders.blank? ),
("LIMIT #{taken}" unless taken.blank? ),
("OFFSET #{skipped}" unless skipped.blank? )
].compact.join("\n")
diff --git a/lib/arel/relations/utilities/compound.rb b/lib/arel/relations/utilities/compound.rb
index a91cec1127..b1e8054d4d 100644
--- a/lib/arel/relations/utilities/compound.rb
+++ b/lib/arel/relations/utilities/compound.rb
@@ -5,7 +5,7 @@ module Arel
delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?,
:column_for, :engine, :table, :table_sql,
:to => :relation
-
+
[:attributes, :wheres, :groupings, :orders].each do |operation_name|
operation = <<-OPERATION
def #{operation_name}
@@ -15,4 +15,4 @@ module Arel
class_eval operation, __FILE__, __LINE__
end
end
-end \ No newline at end of file
+end
diff --git a/spec/arel/unit/relations/alias_spec.rb b/spec/arel/unit/relations/alias_spec.rb
index 5327154fa8..460a0ed0df 100644
--- a/spec/arel/unit/relations/alias_spec.rb
+++ b/spec/arel/unit/relations/alias_spec.rb
@@ -5,14 +5,14 @@ module Arel
before do
@relation = Table.new(:users)
end
-
+
describe '==' do
it "obtains if the objects are the same" do
Alias.new(@relation).should_not == Alias.new(@relation)
(aliaz = Alias.new(@relation)).should == aliaz
end
end
-
+
describe '#to_sql' do
describe 'when there is no ambiguity' do
it 'does not alias table names anywhere a table name can appear' do
@@ -26,11 +26,11 @@ module Arel
SELECT `users`.`id`
FROM `users`
WHERE `users`.`id` = 1
- ORDER BY `users`.`id`
GROUP BY `users`.`id`
+ ORDER BY `users`.`id`
")
end
end
end
end
-end \ No newline at end of file
+end