From 78b5b5783776f57a47e480db4bd83b15db988909 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Mon, 19 May 2008 17:55:49 -0700 Subject: some convenience methods --- lib/arel.rb | 1 + lib/arel/arel.rb | 3 +++ lib/arel/relations/relation.rb | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 lib/arel/arel.rb (limited to 'lib') diff --git a/lib/arel.rb b/lib/arel.rb index b4fae65f73..f56005c2ed 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -4,6 +4,7 @@ require 'rubygems' require 'activesupport' require 'activerecord' +require 'arel/arel' require 'arel/extensions' require 'arel/sql' require 'arel/predicates' diff --git a/lib/arel/arel.rb b/lib/arel/arel.rb new file mode 100644 index 0000000000..892be854ee --- /dev/null +++ b/lib/arel/arel.rb @@ -0,0 +1,3 @@ +def Arel(name, engine = Arel::Table.engine) + Arel::Table.new(name, engine) +end \ No newline at end of file diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index 4440fb1c1d..6e0413232f 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -57,26 +57,26 @@ module Arel include Enumerable module Operable - def join(other = nil, join_type = "INNER JOIN") - case other + def join(other_relation = nil, join_type = "INNER JOIN") + case other_relation when String - Join.new(other, self) + Join.new(other_relation, self) when Relation - JoinOperation.new(join_type, self, other) + JoinOperation.new(join_type, self, other_relation) else self end end - def outer_join(other = nil) - join(other, "LEFT OUTER JOIN") + def outer_join(other_relation = nil) + join(other_relation, "LEFT OUTER JOIN") end - def where(*predicates) + def where(*predicates, &block) predicates.all?(&:blank?) ? self : Where.new(self, *predicates) end - def project(*attributes) + def project(*attributes, &block) attributes.all?(&:blank?) ? self : Project.new(self, *attributes) end @@ -84,7 +84,7 @@ module Arel Alias.new(self) end - def order(*attributes) + def order(*attributes, &block) attributes.all?(&:blank?) ? self : Order.new(self, *attributes) end @@ -96,7 +96,7 @@ module Arel skipped.blank?? self : Skip.new(self, skipped) end - def group(*groupings) + def group(*groupings, &block) groupings.all?(&:blank?) ? self : Group.new(self, *groupings) end -- cgit v1.2.3