squeel 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,6 @@ module Squeel
45
45
  r = r.clone
46
46
  association_name ||= infer_association_for_relation_merge(r)
47
47
  prepare_relation_for_association_merge!(r, association_name)
48
- self.joins_values += [association_name] if reflect_on_association(association_name)
49
48
  end
50
49
 
51
50
  super(r)
@@ -64,7 +63,11 @@ module Squeel
64
63
  def prepare_relation_for_association_merge!(r, association_name)
65
64
  r.where_values.map! {|w| Squeel::Visitors::PredicateVisitor.can_accept?(w) ? {association_name => w} : w}
66
65
  r.having_values.map! {|h| Squeel::Visitors::PredicateVisitor.can_accept?(h) ? {association_name => h} : h}
67
- r.joins_values.map! {|j| [Symbol, Hash, Nodes::Stub, Nodes::Join].include?(j.class) ? {association_name => j} : j}
66
+ r.group_values.map! {|g| Squeel::Visitors::AttributeVisitor.can_accept?(g) ? {association_name => g} : g}
67
+ r.order_values.map! {|o| Squeel::Visitors::AttributeVisitor.can_accept?(o) ? {association_name => o} : o}
68
+ r.select_values.map! {|s| Squeel::Visitors::AttributeVisitor.can_accept?(s) ? {association_name => s} : s}
69
+ r.joins_values.map! {|j| [Symbol, Hash, Nodes::Stub, Nodes::Join, Nodes::KeyPath].include?(j.class) ? {association_name => j} : j}
70
+ r.includes_values.map! {|i| [Symbol, Hash, Nodes::Stub, Nodes::Join, Nodes::KeyPath].include?(i.class) ? {association_name => i} : i}
68
71
  end
69
72
 
70
73
  def build_arel
@@ -1,3 +1,3 @@
1
1
  module Squeel
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -14,6 +14,12 @@ module Squeel
14
14
  end
15
15
  end
16
16
 
17
+ it 'joins has_many :through associations' do
18
+ @jd.send(:build, :authored_article_comments)
19
+ @jd.join_associations.should have(1).association
20
+ @jd.join_associations.first.table_name.should eq 'comments'
21
+ end
22
+
17
23
  it 'joins with stubs' do
18
24
  @jd.send(:build, Nodes::Stub.new(:articles) => Nodes::Stub.new(:comments))
19
25
  @jd.join_associations.should have(2).associations
@@ -444,6 +444,11 @@ module Squeel
444
444
  block.to_sql.should eq standard.to_sql
445
445
  end
446
446
 
447
+ it 'joins has_many :through associations' do
448
+ relation = Person.joins(:authored_article_comments)
449
+ relation.first.authored_article_comments.first.should eq Comment.first
450
+ end
451
+
447
452
  it 'joins polymorphic belongs_to associations' do
448
453
  relation = Note.joins{notable(Article)}
449
454
  relation.to_sql.should match /"notes"."notable_type" = 'Article'/
@@ -577,7 +582,7 @@ module Squeel
577
582
  end
578
583
 
579
584
  it 'merges relations with a different base' do
580
- relation = Person.where{name == 'bob'}.merge(Article.where{title == 'Hello world!'})
585
+ relation = Person.where{name == 'bob'}.joins(:articles).merge(Article.where{title == 'Hello world!'})
581
586
  sql = relation.to_sql
582
587
  sql.should match /INNER JOIN "articles" ON "articles"."person_id" = "people"."id"/
583
588
  sql.should match /"people"."name" = 'bob'/
@@ -11,7 +11,7 @@ class Person < ActiveRecord::Base
11
11
  has_many :articles
12
12
  has_many :comments
13
13
  has_many :authored_article_comments, :through => :articles,
14
- :class_name => 'Comment', :foreign_key => :person_id
14
+ :source => :comments
15
15
  has_many :notes, :as => :notable
16
16
  end
17
17
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: squeel
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.1
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ernie Miller
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-11 00:00:00 Z
13
+ date: 2011-05-13 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -147,7 +147,7 @@ files:
147
147
  - spec/spec_helper.rb
148
148
  - spec/squeel/adapters/active_record/context_spec.rb
149
149
  - spec/squeel/adapters/active_record/join_association_spec.rb
150
- - spec/squeel/adapters/active_record/join_depdendency_spec.rb
150
+ - spec/squeel/adapters/active_record/join_dependency_spec.rb
151
151
  - spec/squeel/adapters/active_record/relation_spec.rb
152
152
  - spec/squeel/dsl_spec.rb
153
153
  - spec/squeel/nodes/function_spec.rb
@@ -208,7 +208,7 @@ test_files:
208
208
  - spec/spec_helper.rb
209
209
  - spec/squeel/adapters/active_record/context_spec.rb
210
210
  - spec/squeel/adapters/active_record/join_association_spec.rb
211
- - spec/squeel/adapters/active_record/join_depdendency_spec.rb
211
+ - spec/squeel/adapters/active_record/join_dependency_spec.rb
212
212
  - spec/squeel/adapters/active_record/relation_spec.rb
213
213
  - spec/squeel/dsl_spec.rb
214
214
  - spec/squeel/nodes/function_spec.rb