postgres_ext 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3246d3eb02a37797d39a1e4c9eb7ef17e010b2b
4
- data.tar.gz: 569c3f94c31b6b7979eb95da5d5ab2dcb5f376cb
3
+ metadata.gz: 98ff2c9bb400e566e90b0eee78c7fbc3c4d20626
4
+ data.tar.gz: 235aeec3bafdf81928a2abadd4e19dcfdfcf26dd
5
5
  SHA512:
6
- metadata.gz: 5ab51fcf131d599a871238d2fd1738b43fc316df96f2810a9045bf513d515e29bfa13008077cf7cccf4349bd7cfbf569812156b9cd62c764d0a830328810dd9d
7
- data.tar.gz: ba34c9e19290e4691dc28c337dc7aaa13b121b0fff51499a4720e16f816609e140115508f02c0a959971e74597ad46202822a7fabbb360d3b2d9c402ac533709
6
+ metadata.gz: 2fbaa25ab99012bea7aa49c91c95ccd088f8abe1b51a78b584454e661073224082782eeedca079b6d763d0fd0ac9a1ed44cfc5cd616eaa5440ab9d2b5bbbbbf5
7
+ data.tar.gz: 8991fc711864a429fcc3b95a9a76dbcd353f5723597d3027651934d5ef36208dcdf9fa3ee173dae52e821757582c7d2e39431326ad4971150564fe0ae47cd425
@@ -1,3 +1,7 @@
1
+ ## 2.4.1
2
+
3
+ * Fixes error when creating a join between STI related models - edpaget
4
+
1
5
  ## 2.4.0
2
6
 
3
7
  * Fixes missing CTEProxy delegate - eidge
data/Rakefile CHANGED
@@ -116,6 +116,8 @@ namespace :db do
116
116
  t.string "categories", array: true
117
117
  t.datetime "created_at"
118
118
  t.datetime "updated_at"
119
+ t.integer "parent_id"
120
+ t.string "type"
119
121
  end
120
122
 
121
123
  puts 'Database migrated'
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
  when Array
8
8
  engine = attribute.relation.engine
9
9
  column = engine.connection.schema_cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s }
10
- if column && column.array
10
+ if column && column.respond_to?(:array) && column.array
11
11
  attribute.eq(value)
12
12
  else
13
13
  values = value.to_a.map {|x| x.is_a?(Base) ? x.id : x}
@@ -12,7 +12,7 @@ module ActiveRecord
12
12
  def call_with_feature(attribute, value)
13
13
  engine = attribute.relation.engine
14
14
  column = engine.connection.schema_cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s }
15
- if column.array
15
+ if column && column.respond_to?(:array) && column.array
16
16
  attribute.eq(value)
17
17
  else
18
18
  call_without_feature(attribute, value)
@@ -6,7 +6,16 @@ module Arel
6
6
  private
7
7
 
8
8
  def visit_Array o, a
9
- column = a.relation.engine.connection.schema_cache.columns(a.relation.name).find { |col| col.name == a.name.to_s } if a
9
+ column = case a.try(:relation)
10
+ when Arel::Nodes::TableAlias, NilClass
11
+ # noop Prevent from searching for table alias name in schema cache
12
+ # which won't exist for aliased table when used with Single Table
13
+ # Inheritance. see dockyard/postgres_ext#154
14
+ else
15
+ a.relation.engine.connection.schema_cache.columns(a.relation.name)
16
+ .find { |col| col.name == a.name.to_s }
17
+ end
18
+
10
19
  if column && column.respond_to?(:array) && column.array
11
20
  quoted o, a
12
21
  else
@@ -1,3 +1,3 @@
1
1
  module PostgresExt
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.1'
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ describe "Join queries" do
4
+ describe ".joins(:parent_tag) with STI" do
5
+ it 'returns a valid sql query' do
6
+ query = ChildTag.joins(:parent_tag).to_sql
7
+ query.must_match("SELECT \"tags\".* FROM \"tags\" INNER JOIN \"tags\" \"parent_tags_tags\" ON \"parent_tags_tags\".\"id\" = \"tags\".\"parent_id\" AND \"parent_tags_tags\".\"type\" IN ('ParentTag') WHERE \"tags\".\"type\" IN ('ChildTag')")
8
+ end
9
+ end
10
+ end
@@ -27,6 +27,13 @@ class Tag < ActiveRecord::Base
27
27
  belongs_to :person
28
28
  end
29
29
 
30
+ class ParentTag < Tag
31
+ end
32
+
33
+ class ChildTag < Tag
34
+ belongs_to :parent_tag, foreign_key: :parent_id
35
+ end
36
+
30
37
  DatabaseCleaner.strategy = :deletion
31
38
 
32
39
  class MiniTest::Spec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan McClain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -195,6 +195,7 @@ files:
195
195
  - test/queries/array_queries_test.rb
196
196
  - test/queries/common_table_expression_test.rb
197
197
  - test/queries/contains_test.rb
198
+ - test/queries/join_query_test.rb
198
199
  - test/queries/sanity_test.rb
199
200
  - test/queries/window_functions_test.rb
200
201
  - test/test_helper.rb
@@ -228,6 +229,7 @@ test_files:
228
229
  - test/queries/array_queries_test.rb
229
230
  - test/queries/common_table_expression_test.rb
230
231
  - test/queries/contains_test.rb
232
+ - test/queries/join_query_test.rb
231
233
  - test/queries/sanity_test.rb
232
234
  - test/queries/window_functions_test.rb
233
235
  - test/test_helper.rb