diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-11 15:22:22 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-11 15:22:22 -0700 |
commit | eee3a766160cd32a4d9b5e1352858597005c9cee (patch) | |
tree | 10b58d7c350198a0598e1387e221fb1fe8fc0078 /lib/active_relation | |
parent | ad50e772d32c261e4463d67d5c50a25b21a36370 (diff) | |
download | rails-eee3a766160cd32a4d9b5e1352858597005c9cee.tar.gz rails-eee3a766160cd32a4d9b5e1352858597005c9cee.tar.bz2 rails-eee3a766160cd32a4d9b5e1352858597005c9cee.zip |
string passthrough for joins
Diffstat (limited to 'lib/active_relation')
-rw-r--r-- | lib/active_relation/primitives/attribute.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/join.rb | 6 | ||||
-rw-r--r-- | lib/active_relation/relations/nil.rb | 5 | ||||
-rw-r--r-- | lib/active_relation/relations/table.rb | 2 |
5 files changed, 11 insertions, 5 deletions
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb index ddf5ef5e07..9685d2ab4a 100644 --- a/lib/active_relation/primitives/attribute.rb +++ b/lib/active_relation/primitives/attribute.rb @@ -4,7 +4,7 @@ module ActiveRelation delegate :engine, :to => :relation def initialize(relation, name, options = {}) - @relation, @name, @alias, @ancestor, @column = relation, name, options[:alias], options[:ancestor] + @relation, @name, @alias, @ancestor = relation, name, options[:alias], options[:ancestor] end def alias_or_name diff --git a/lib/active_relation/relations.rb b/lib/active_relation/relations.rb index 7776fd3d18..d914fca094 100644 --- a/lib/active_relation/relations.rb +++ b/lib/active_relation/relations.rb @@ -1,4 +1,5 @@ require 'active_relation/relations/relation' +require 'active_relation/relations/nil' require 'active_relation/relations/compound' require 'active_relation/relations/writing' require 'active_relation/relations/table' diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb index ab5f440d9e..c5ce47b555 100644 --- a/lib/active_relation/relations/join.rb +++ b/lib/active_relation/relations/join.rb @@ -6,7 +6,7 @@ module ActiveRelation hash_on :relation1 - def initialize(join_sql, relation1, relation2, *predicates) + def initialize(join_sql, relation1, relation2 = Nil.new, *predicates) @join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates end @@ -40,9 +40,9 @@ module ActiveRelation this_join = [ join_sql, externalize(relation2).table_sql, - "ON", + ("ON" unless predicates.blank?), predicates.collect { |p| p.bind(self).to_sql }.join(' AND ') - ].join(" ") + ].compact.join(" ") [relation1.joins, relation2.joins, this_join].compact.join(" ") end diff --git a/lib/active_relation/relations/nil.rb b/lib/active_relation/relations/nil.rb new file mode 100644 index 0000000000..b063db92c9 --- /dev/null +++ b/lib/active_relation/relations/nil.rb @@ -0,0 +1,5 @@ +module ActiveRelation + class Nil < Relation + def table_sql; '' end + end +end
\ No newline at end of file diff --git a/lib/active_relation/relations/table.rb b/lib/active_relation/relations/table.rb index 72682bee55..5ad27c1fcf 100644 --- a/lib/active_relation/relations/table.rb +++ b/lib/active_relation/relations/table.rb @@ -45,7 +45,7 @@ module ActiveRelation end def table_sql - "#{engine.quote_table_name(name)}" + engine.quote_table_name(name) end private |