active_record_or 1.0.0 → 1.0.1
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 +7 -0
- data/Rakefile +7 -0
- data/lib/active_record_or.rb +5 -1
- data/lib/active_record_or/version.rb +1 -1
- data/test/active_record_or_test.rb +6 -0
- metadata +4 -3
data/README.md
CHANGED
@@ -18,6 +18,13 @@ This would let you write handy things like
|
|
18
18
|
to_harass = Blog.joins(:author).where('authors.name' => 'Julian')\
|
19
19
|
.or.generally_disliked
|
20
20
|
|
21
|
+
Also, if you call `or` on a condition-less scope, it will be ignored:
|
22
|
+
|
23
|
+
Blog.scoped.or.where(:name => 'Julian')
|
24
|
+
|
25
|
+
This means you can start off the query with an `or`, in case you don't
|
26
|
+
know the state of the scope.
|
27
|
+
|
21
28
|
The end.
|
22
29
|
|
23
30
|
Credits
|
data/Rakefile
CHANGED
data/lib/active_record_or.rb
CHANGED
@@ -7,8 +7,12 @@ module ActiveRecordOr
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def method_missing(method, *args, &block)
|
10
|
+
last_left_constraint = @left.constraints.last
|
11
|
+
return @left.send(method, *args, &block) unless last_left_constraint
|
12
|
+
|
10
13
|
raw_right = @left.unscoped.send(method, *args, &block)
|
11
|
-
|
14
|
+
|
15
|
+
or_based_constraints = last_left_constraint.or(raw_right.constraints.last)
|
12
16
|
right = @left.send(method, *args, &block)
|
13
17
|
right.where_values = [or_based_constraints]
|
14
18
|
right
|
@@ -48,5 +48,11 @@ describe ActiveRecord::Relation do
|
|
48
48
|
to_harass.join_sql.must_equal(
|
49
49
|
%(INNER JOIN "authors" ON "authors"."id" = "blogs"."author_id") )
|
50
50
|
end
|
51
|
+
|
52
|
+
it "works with no conditions on the left side" do
|
53
|
+
sql = Blog.scoped.or.where(:name => 'Julian')
|
54
|
+
|
55
|
+
sql.to_sql.must_equal "SELECT \"blogs\".* FROM \"blogs\" WHERE \"blogs\".\"name\" = 'Julian'"
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_or
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Adds OR logic to ActiveRecord
|
15
15
|
email:
|
@@ -47,10 +47,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project: active_record_or
|
50
|
-
rubygems_version: 1.8.
|
50
|
+
rubygems_version: 1.8.24
|
51
51
|
signing_key:
|
52
52
|
specification_version: 3
|
53
53
|
summary: Chain scopes with 'or'
|
54
54
|
test_files:
|
55
55
|
- test/active_record_or_test.rb
|
56
56
|
- test/test_helper.rb
|
57
|
+
has_rdoc:
|