aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-26 13:45:31 -0700
committerSean Griffin <sean@thoughtbot.com>2014-11-29 16:08:51 -0700
commit7508284800f67b4611c767bff9eae7045674b66f (patch)
tree9f16f258662c4b0165f1ee255eddb3f07d6aeeb6 /lib
parentec083687a96af1f35f9fb9e75611cc4bf4f5bf81 (diff)
downloadrails-7508284800f67b4611c767bff9eae7045674b66f.tar.gz
rails-7508284800f67b4611c767bff9eae7045674b66f.tar.bz2
rails-7508284800f67b4611c767bff9eae7045674b66f.zip
Remove engine from the constructor arguments `Arel::Table`
It is never used outside of convenience methods which are only used in tests. In practice, it just made constructing tables more complicated on the rails side. This is the minimum possible change to remove the constructor argument, but continue to have the tests passing. I'm not sure if we have a reason to keep `project` and friends, and the solution might actually just be to remove the engine from `SelectManager` and friends. As such I've held off on deleting those methods. We need to figure out what to do with `Table#from`. It's old invocation, which read `table.from(table)` was certainly nonsensical.
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/table.rb61
1 files changed, 21 insertions, 40 deletions
diff --git a/lib/arel/table.rb b/lib/arel/table.rb
index fb86c03404..d534c44fa1 100644
--- a/lib/arel/table.rb
+++ b/lib/arel/table.rb
@@ -11,20 +11,18 @@ module Arel
# TableAlias and Table both have a #table_name which is the name of the underlying table
alias :table_name :name
- def initialize name, engine = Table.engine
+ def initialize name, options = {}
@name = name.to_s
- @engine = engine
@columns = nil
@aliases = []
- @table_alias = nil
-
- if Hash === engine
- @engine = engine[:engine] || Table.engine
-
- # Sometime AR sends an :as parameter to table, to let the table know
- # that it is an Alias. We may want to override new, and return a
- # TableAlias node?
- @table_alias = engine[:as] unless engine[:as].to_s == @name
+ @engine = Table.engine
+
+ # Sometime AR sends an :as parameter to table, to let the table know
+ # that it is an Alias. We may want to override new, and return a
+ # TableAlias node?
+ @table_alias = options[:as]
+ if @table_alias.to_s == @name
+ @table_alias = nil
end
end
@@ -34,12 +32,12 @@ module Arel
end
end
- def from table
- SelectManager.new(@engine, table)
+ def from engine = Table.engine
+ SelectManager.new(engine, self)
end
def join relation, klass = Nodes::InnerJoin
- return from(self) unless relation
+ return from unless relation
case relation
when String, Nodes::SqlLiteral
@@ -47,7 +45,7 @@ module Arel
klass = Nodes::StringJoin
end
- from(self).join(relation, klass)
+ from.join(relation, klass)
end
def outer_join relation
@@ -55,55 +53,39 @@ module Arel
end
def group *columns
- from(self).group(*columns)
+ from.group(*columns)
end
def order *expr
- from(self).order(*expr)
+ from.order(*expr)
end
def where condition
- from(self).where condition
+ from.where condition
end
def project *things
- from(self).project(*things)
+ from.project(*things)
end
def take amount
- from(self).take amount
+ from.take amount
end
def skip amount
- from(self).skip amount
+ from.skip amount
end
def having expr
- from(self).having expr
+ from.having expr
end
def [] name
::Arel::Attribute.new self, name
end
- def select_manager
- SelectManager.new(@engine)
- end
-
- def insert_manager
- InsertManager.new(@engine)
- end
-
- def update_manager
- UpdateManager.new(@engine)
- end
-
- def delete_manager
- DeleteManager.new(@engine)
- end
-
def hash
- # Perf note: aliases, table alias and engine is excluded from the hash
+ # Perf note: aliases and table alias is excluded from the hash
# aliases can have a loop back to this table breaking hashes in parent
# relations, for the vast majority of cases @name is unique to a query
@name.hash
@@ -112,7 +94,6 @@ module Arel
def eql? other
self.class == other.class &&
self.name == other.name &&
- self.engine == other.engine &&
self.aliases == other.aliases &&
self.table_alias == other.table_alias
end