squeel 0.7.2 → 0.7.3

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.
data/README.md CHANGED
@@ -30,9 +30,27 @@ Squeel enhances the normal ActiveRecord query methods by enabling them to accept
30
30
  blocks. Inside a block, the Squeel query DSL can be used. Note the use of curly braces
31
31
  in these examples instead of parentheses. `{}` denotes a Squeel DSL query.
32
32
 
33
- Stubs and keypaths are the two primary building blocks used in a Squeel DSL query, so
34
- before we go on, let's take a look at them. Most of the other examples that follow will
35
- be based on this "symbol-less" syntax, so it might look a bit foreign otherwise.
33
+ Stubs and keypaths are the two primary building blocks used in a Squeel DSL query, so we'll
34
+ start by taking a look at them. Most of the other examples that follow will be based on
35
+ this "symbol-less" block syntax.
36
+
37
+ *An important gotcha, before we begin:* The Squeel DSL works its magic using `instance_eval`.
38
+ If you've been working with Ruby for a while, you'll know immediately that this means that
39
+ _inside_ a Squeel DSL block, `self` isn't the same thing that it is _outside_ the block.
40
+
41
+ This carries with it an important implication: <strong>Instance variables and instance methods
42
+ inside the block won't refer to your object's variables/methods.</strong>
43
+
44
+ Don't worry, Squeel's got you covered. Use one of the following methods to get access
45
+ to your object's methods and variables:
46
+
47
+ 1. Assign the variable locally before the DSL block, and access it as you would
48
+ normally.
49
+ 2. Supply and arity to the DSL block, as in `Person.where{|dsl| dsl.name == @my_name}`
50
+ Downside: You'll need to prefix stubs, keypaths, and functions (explained below)
51
+ with the DSL object.
52
+ 3. Wrap the method or instance variable inside the block with `my{}`.
53
+ `Person.where{name == my{some_method_to_return_a_name}}`
36
54
 
37
55
  ### Stubs
38
56
 
@@ -258,7 +258,7 @@ module Squeel
258
258
  nodes.map { |node|
259
259
  case node
260
260
  when Arel::Nodes::Equality
261
- node
261
+ node if node.left.relation.name == table_name
262
262
  when Arel::Nodes::Grouping
263
263
  find_equality_predicates([node.expr])
264
264
  when Arel::Nodes::And
@@ -272,7 +272,7 @@ module Squeel
272
272
  nodes.map { |node|
273
273
  case node
274
274
  when Arel::Nodes::Equality
275
- node
275
+ node if node.left.relation.name == table_name
276
276
  when Arel::Nodes::Grouping
277
277
  find_equality_predicates([node.expr])
278
278
  when Arel::Nodes::And
@@ -1,3 +1,3 @@
1
1
  module Squeel
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -570,6 +570,17 @@ module Squeel
570
570
  @person.name.should eq 'joe'
571
571
  end
572
572
 
573
+ it 'creates through a join model' do
574
+ Article.transaction do
575
+ article = Article.first
576
+ person = article.commenters.create(:name => 'Ernie Miller')
577
+ person.should be_persisted
578
+ person.comments.should have(1).comment
579
+ person.comments.first.article.should eq article
580
+ raise ::ActiveRecord::Rollback
581
+ end
582
+ end
583
+
573
584
  end
574
585
 
575
586
  describe '#merge' do
@@ -591,7 +602,7 @@ module Squeel
591
602
 
592
603
  it 'does not break hm:t with conditions' do
593
604
  relation = Person.first.condition_article_comments
594
- sql = relation.to_sql
605
+ sql = relation.scoped.to_sql
595
606
  sql.should match /"articles"."title" = 'Condition'/
596
607
  end
597
608
 
@@ -22,6 +22,7 @@ class Article < ActiveRecord::Base
22
22
  has_many :comments
23
23
  has_and_belongs_to_many :tags
24
24
  has_many :notes, :as => :notable
25
+ has_many :commenters, :through => :comments, :source => :person
25
26
  end
26
27
 
27
28
  class Comment < ActiveRecord::Base
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: squeel
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.2
5
+ version: 0.7.3
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-19 00:00:00 Z
13
+ date: 2011-05-24 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord