diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-07 11:44:32 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-07 11:44:32 -0800 |
commit | 89194f5976d09a62f967e550daeda41ac0b9de48 (patch) | |
tree | 3d479e589e98e4dc6eabdce2ddccca97821441dc /lib/arel | |
parent | b9d2cd97888f76cf7c15fd1a7167c638950071c1 (diff) | |
download | rails-89194f5976d09a62f967e550daeda41ac0b9de48.tar.gz rails-89194f5976d09a62f967e550daeda41ac0b9de48.tar.bz2 rails-89194f5976d09a62f967e550daeda41ac0b9de48.zip |
adding a join factory method on the select manager
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/factory_methods.rb | 9 | ||||
-rw-r--r-- | lib/arel/nodes/string_join.rb | 4 | ||||
-rw-r--r-- | lib/arel/table.rb | 7 | ||||
-rw-r--r-- | lib/arel/tree_manager.rb | 1 |
4 files changed, 16 insertions, 5 deletions
diff --git a/lib/arel/factory_methods.rb b/lib/arel/factory_methods.rb new file mode 100644 index 0000000000..23d668c8e5 --- /dev/null +++ b/lib/arel/factory_methods.rb @@ -0,0 +1,9 @@ +module Arel + ### + # Methods for creating various nodes + module FactoryMethods + def create_join from, to, on = nil, klass = Nodes::InnerJoin + klass.new(from, to, on) + end + end +end diff --git a/lib/arel/nodes/string_join.rb b/lib/arel/nodes/string_join.rb index ea7912f92b..b24e91b6b8 100644 --- a/lib/arel/nodes/string_join.rb +++ b/lib/arel/nodes/string_join.rb @@ -3,8 +3,8 @@ module Arel class StringJoin < Arel::Nodes::Join undef :constraint - def initialize left, right - super(left, right, nil) + def initialize left, right, on = nil + super end end end diff --git a/lib/arel/table.rb b/lib/arel/table.rb index e7a626a4c6..ceb81705b3 100644 --- a/lib/arel/table.rb +++ b/lib/arel/table.rb @@ -1,6 +1,7 @@ module Arel class Table include Arel::Crud + include Arel::FactoryMethods @engine = nil class << self; attr_accessor :engine; end @@ -57,10 +58,10 @@ module Arel case relation when String, Nodes::SqlLiteral raise if relation.blank? - from Nodes::StringJoin.new(self, relation) - else - from klass.new(self, relation, nil) + klass = Nodes::StringJoin end + + from create_join(self, relation, nil, klass) end def group *columns diff --git a/lib/arel/tree_manager.rb b/lib/arel/tree_manager.rb index 2fa770a0e3..5722baca77 100644 --- a/lib/arel/tree_manager.rb +++ b/lib/arel/tree_manager.rb @@ -2,6 +2,7 @@ module Arel class TreeManager # FIXME: Remove this. include Arel::Relation + include Arel::FactoryMethods attr_accessor :visitor attr_reader :ast, :engine |