squeel 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
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
|
-
|
35
|
-
|
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
|
|
data/lib/squeel/version.rb
CHANGED
@@ -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
|
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: squeel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
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-
|
13
|
+
date: 2011-05-24 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|