directiverecord 0.1.10 → 0.1.11

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDNjNWU1NTk0ZmM0MTViZDgyZDAxMmJkNmI5OWYwZTQ4MGUzNmIzZQ==
4
+ OTcxNmYzYThjODg4OGZmZGVhZWIwMjQzZmQ2ZGExY2I2YWI1YWI3NA==
5
5
  data.tar.gz: !binary |-
6
- MDEwNjA5YmQ2ZTRkM2Q2ZjFjZDY3MGViYTE0ZTJmN2YyZDQyMzQxOA==
6
+ YTdmNzI2MjM4ZTI4NzA3NDBmZGI2NTAwMGI1OGZhNDAwNDJjNzBiNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmE4ZjdjNzVhNzRhYjk4NjI5NjkzMzY0ZDQyZDE3OTAxMTM2YWVjODNmZDlm
10
- NGRmN2RkMzBkMGFmZDUyMDc5ODk1YjlhNjUxNDU3NGU2NDE3YTFhNzkzZWRl
11
- ZTkzNmE3YTJhODA0ZTIyMjBhZDY2OGI3ZmIxY2ZiZWYwOTUxY2I=
9
+ ZjhiNmRhMzU0ZWRkOWQ1ODVhMWExNzE1MzY3ZGMwYWMzZTkwMmI0MDlmYjA2
10
+ OGM5NzcwYWM1NjE5ZTBiMzcxZDQxYzA3NGZlZWYxZDA4M2RmYjU1OWI0ZTE5
11
+ YzEzMDQyYTEwMjkwNGFiYzg0MjBkYTQyNjU2ZmM2NGM4ZmE0YWY=
12
12
  data.tar.gz: !binary |-
13
- NmNlNjkyZDE1NjRhZjI2NmZlNDk3MmM0M2IzYjJiZDUxY2ZhMjg3MWM0Mjc2
14
- NjU4NjM0M2YwZWY3ZTY0MGZlZWRjN2VkN2M0ZjU0ZDBjOWVjYjdlY2NlMTE1
15
- MDJjMWVmMmYwZDk1NTE0YTE4MDAwM2M0MDk3OTNiYzEyMDQ5MDc=
13
+ YmM4OTgxZDc3NzJjZTY0ZjhiNjQwYjhiNDZhYTc4OWU5ZDgyNzY5ZmI0MGY5
14
+ MTBjZDg2NTYxOWYyZTk3MzM5NDUxYjQyMjRmZTQxMDFmZDg4NGM1OTk0MzIy
15
+ NmExMTA4MmZlN2EzMGQwYjllZGFiYzc0M2JlYzI1OWMzMDJjNzc=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.11 (March 6, 2015)
4
+
5
+ * Counting ‘DISTINCT id’ instead of ‘*’ in ActiveRecord::Relation#count(:all) override
6
+ * Leaving sub selects alone
7
+
3
8
  == Version 0.1.10 (March 5, 2015)
4
9
 
5
10
  * Overridden ActiveRecord::Relation#count(:all) to hook in DirectiveRecord query mechanism
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -17,7 +17,7 @@ module ActiveRecord
17
17
 
18
18
  def count(column_name = nil, options = {})
19
19
  if !loaded? && (column_name == :all) && (options == {})
20
- qry("COUNT(*)")[0][0]
20
+ qry("COUNT(DISTINCT id)")[0][0]
21
21
  else
22
22
  original_count column_name, options
23
23
  end
@@ -296,6 +296,7 @@ SQL
296
296
  end
297
297
 
298
298
  def prepend_base_alias(sql, aliases = {})
299
+ return sql if sql.include?("SELECT")
299
300
  columns = base.columns_hash.keys
300
301
  sql.gsub(/("[^"]*"|'[^']*'|`[^`]*`|[a-zA-Z_#{aggregate_delimiter}]+(\.[a-zA-Z_\*]+)*)/) do
301
302
  columns.include?($1) ? "#{base_alias}.#{$1}" : begin
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 10
4
+ TINY = 11
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -47,7 +47,7 @@ module Unit
47
47
  describe "when not loaded" do
48
48
  it "uses qry to count the records" do
49
49
  @relation.expects(:loaded?).returns(false)
50
- @relation.expects(:qry).with("COUNT(*)").returns([[1982]])
50
+ @relation.expects(:qry).with("COUNT(DISTINCT id)").returns([[1982]])
51
51
  assert_equal 1982, @relation.count(:all)
52
52
  end
53
53
  end
@@ -17,7 +17,17 @@ module Unit
17
17
  FROM offices `o`
18
18
  }
19
19
  ),
20
- Office.to_qry("id, city")
20
+ Office.to_qry("id", "city")
21
+ )
22
+
23
+ assert_equal(
24
+ strip(
25
+ %Q{
26
+ SELECT `o`.id, `o`.city, (SELECT o1.id FROM offices o1)
27
+ FROM offices `o`
28
+ }
29
+ ),
30
+ Office.to_qry("id", "city", "(SELECT o1.id FROM offices o1)")
21
31
  )
22
32
 
23
33
  assert_equal(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directiverecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord