mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
string passthrough for joins
This commit is contained in:
parent
ad50e772d3
commit
eee3a76616
9 changed files with 32 additions and 23 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
coverage/*
|
||||
coverage/*
|
||||
*.DS_Store
|
||||
|
|
16
doc/TODO
16
doc/TODO
|
@ -1,8 +1,5 @@
|
|||
todo:
|
||||
- re-evaluate bind -- does bind belong inside the relation / predicate classes or in the factory methods?
|
||||
- - mock out database
|
||||
- #bind in Attribute and Expression should be doing a descend?
|
||||
- try to make aggegration testing in join spec to be a bit more unit-like
|
||||
- mock out database
|
||||
- finish pending tests
|
||||
- test relation, table reset
|
||||
- standardize quoting
|
||||
|
@ -14,12 +11,6 @@ todo:
|
|||
:joins=>"INNER JOIN posts ON comments.post_id = posts.id"
|
||||
- shit this one is hard at the moment.
|
||||
|
||||
- need adapters for this form:
|
||||
{:conditions=>["approved = ?", false]}
|
||||
{:conditions=>{:approved=>false}}
|
||||
{:conditions=>{"topics.approved"=>false}}
|
||||
{:conditions=>{:address=>#<Address:0x3489b3c @street="Funny Street", @country="Loony Land", @city="Scary Town">, "customers.name"=>"David1"}}
|
||||
|
||||
- cache expiry on write
|
||||
- rewrite of querycache test in light of this
|
||||
- rename the tion (Selection) classes so that words that don't end in tion don't seem inconsistent
|
||||
|
@ -67,3 +58,8 @@ done:
|
|||
- orderings
|
||||
- relation inclusion when given an array (1,2,3,4) should quote the elements using the appropriate quoting formatter taken from the attribute
|
||||
- descend on array, along with bind written in terms of it
|
||||
- re-evaluate bind -- does bind belong inside the relation / predicate classes or in the factory methods?
|
||||
|
||||
icebox:
|
||||
- #bind in Attribute and Expression should be doing a descend?
|
||||
- try to make aggegration testing in join spec to be a bit more unit-like
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
5
lib/active_relation/relations/nil.rb
Normal file
5
lib/active_relation/relations/nil.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module ActiveRelation
|
||||
class Nil < Relation
|
||||
def table_sql; '' end
|
||||
end
|
||||
end
|
|
@ -45,7 +45,7 @@ module ActiveRelation
|
|||
end
|
||||
|
||||
def table_sql
|
||||
"#{engine.quote_table_name(name)}"
|
||||
engine.quote_table_name(name)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -108,7 +108,7 @@ module ActiveRelation
|
|||
end
|
||||
end
|
||||
|
||||
describe 'with aggregated relations' do
|
||||
describe 'when joining aggregated relations' do
|
||||
before do
|
||||
@aggregation = @relation2 \
|
||||
.aggregate(@relation2[:user_id], @relation2[:id].count) \
|
||||
|
@ -157,6 +157,16 @@ module ActiveRelation
|
|||
")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when joining with a string' do
|
||||
it "passes the string through to the where clause" do
|
||||
Join.new("INNER JOIN ON asdf", @relation1).to_sql.should be_like("
|
||||
SELECT `users`.`id`, `users`.`name`
|
||||
FROM `users`
|
||||
INNER JOIN ON asdf
|
||||
")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -48,12 +48,8 @@ module ActiveRelation
|
|||
end
|
||||
|
||||
describe 'when given a string' do
|
||||
before do
|
||||
@string = "asdf"
|
||||
end
|
||||
|
||||
it "passes the string through to the where clause" do
|
||||
Selection.new(@relation, @string).to_sql.should be_like("
|
||||
Selection.new(@relation, 'asdf').to_sql.should be_like("
|
||||
SELECT `users`.`id`, `users`.`name`
|
||||
FROM `users`
|
||||
WHERE asdf
|
||||
|
|
Loading…
Reference in a new issue